What's the difference between keep_alive and persistent option for HTTP request?
Can someone explain us the difference in behaviour between the following parameters :
ke开发者_Go百科ep_alive parameter in Zend_Http_Client class ?
and
persistent in Zend_Http_Client_Adapter_Socket class ?
I'd like to understand what I need to do to keep a bunch of HTTPS connection open (to avoid the negociation of the SSL).
Thanks, Gaston
If you use the persistent connection ou should use as well the keep-alive, as without keep Alive HTTP 1.1 connexion your persitent will have to do a lot of work to emulate the job.
Edit : (it was time to eat)
Keepalive settings talks about a quite-short time setting, set by the server. Apache by default handle 15s for Keep-Alive requests, but a current optimized setting is 5s. This is mostly done to help HTTP client downloading js and css attached to a page in the same HTTP connexion. If you can adjust the server settings you can try longest Keep-Alive queries (but be careful, this will limit seriously the number of client accepeted by your server).
Persistent connexion mode is done to really emulate a long-term persistent connexion, the socket opened is not closed at the end of the script. You should be very careful with such setting. Are you in CLI mode? FCGI?. If you're running in an apache process I'm really not sure you'll get the same connexion on the next request on this script (which will may be handle by another apache process), it's even worst if your code is running on several apache servers in a large deployment. And this is for the client (PHP) side, but it can be as well a big pain for the targeted server.
Re-edit: (as something about SSL must be said)
Are you sure you need to optimize SSL negociation time? SSL use Cache, at least on server side, to limit the negociation to the first request. Client side caching of SSL session is maybe done by the PHP stream_socket_client function (which is used by the Zend class. If not you could test a new class from your own (just need to implement the interface) and try using curl, as curl use SSL session caching by default.
KeepAlive means that the connection may be reused over the course of an individual request, though it will be closed at the end of the request. Persistent means that the connection will survive beyond the individual request so-as to be used by a subsequent request on the same PHP process.
FYI, while keep-alive is supposed to reuse the HTTP connection, the adapter class (at least as recently as 1.10) doesn't handle this correctly and opens a new connection regardless of the flag.
精彩评论