ruflin / Elastica

Elastica is a PHP client for elasticsearch
http://elastica.io/
MIT License
2.26k stars 733 forks source link

add curl_close to http connection #472

Open saimaz opened 11 years ago

saimaz commented 11 years ago

Elastica Http Transport object has no curl_close. This causes some connection problems when client is used with http persistent connections.

thorsten commented 11 years ago

+1

ruflin commented 10 years ago

The problem is, that when we don't reuse the connection and close it every time, the calls will be much slower or we will have some memory leaks (as far as I remember that was the problem).

My suggestion would be, that we close the connection in case "persistent" is not set to true for the connection. Would that solve the problem to make it configurable?

thorsten commented 10 years ago

Yes, that would solve our problem, because using persistent connections without closing them creates new connections and after some minutes you'll get thousends of open HTTP connections.

audriusbugas commented 10 years ago

Actually it would be enough to add just availability to close single connection (public method) when it's not needed anymore

saimaz commented 10 years ago

Yes the public method to close connection would be better.

ruflin commented 10 years ago

@audriusb @saimaz Not sure how this would work as you rarely have the Transport object directly. As every client can have multiple connections, for which one you will get the transport and close it?

audriusbugas commented 10 years ago

Actually static resource is created here (for all Transports) https://github.com/ruflin/Elastica/blob/master/lib/Elastica/Transport/Http.php#L175. In my opinion two things are missing:

  1. $_curlConnection should be closed before creating new one with curl_init()
  2. Public static method for closing $_curlConnection would be also useful for destroying resource when application does not need it anymore.
ruflin commented 10 years ago

A static resource for all Transport in one request is created, right? Most of the time php scripts are not long running. So the question is, what happens in case the script ends and the connection was not closed?

In the code, a new connection is only opened in case no other already exists already in this request. Unfortunately we do not have any persistency between the calls (which probably also good).

I agree on point two.

ruflin commented 10 years ago

@audriusb @saimaz Any next steps here?

saimaz commented 10 years ago

We have switched to https://github.com/elasticsearch/elasticsearch-php, sorry ;)

ruflin commented 10 years ago

Ok. I hope the curl_close issue was not the main reason ;-)

saimaz commented 10 years ago

IMO for this particular issue static close connection method would be helpful

ruflin commented 10 years ago

Agree. I will keep the issue open.

stloyd commented 10 years ago

@ruflin I guess this #465 would help a lot with similar problems.

ruflin commented 10 years ago

Agree. Lets hope we get some updates from @webpatser

xavividal commented 7 years ago

Any news?