Can someone explain us the difference in behaviour between the following parameters :
keep_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
Persistent connections between a web client and a server can be reused for more than one exchange of a request and a response. Persistent connections improve network performance because a new connection does not have to be established for each request.
HTTP keep-alive, a.k.a., HTTP persistent connection, is an instruction that allows a single TCP connection to remain open for multiple HTTP requests/responses. By default, HTTP connections close after each request.
Enabling Keep-Alive can help to optimize website's performance and deliver a better user experience. It allows a visitor's browser to reuse a single TCP connection to load page content. Keep-Alive is usually enabled by default on your origin server.
Persistent connections provide a mechanism by which a client and a server can signal the close of a TCP connection. This signaling takes place using the Connection header field (section 14.10). Once a close has been signaled, the client MUST NOT send any more requests on that connection.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With