Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.4

Request #4806 Implement keep-alive support
Submitted: 2005-07-12 11:31 UTC Modified: 2006-10-24 08:18 UTC
From: tjerk dot meesters at gmail dot com Assigned: avb
Status: Closed Package: HTTP_Request
PHP Version: 5_1 CVS-2005-07-12 OS: WinXP
Roadmaps: (Not assigned)    
Subscription  


 [2005-07-12 11:31 UTC] tjerk dot meesters at gmail dot com
Description: ------------ If keep-alive is given in the request headers on the client side, the response is read until eof is found; however, given the nature of keep-alive, the server end waits for another request and the socket is being kept open (for as long as the client specified in the 'keep-alive' header). If content-length is given, this should be used to read exactly the amount necessary. Ofcourse, this should only be done if the server side agrees to use keep-alive (they may refuse to do so in which case the read-until-eof is okay), since this is more efficient.

Comments

 [2005-07-13 01:28 UTC] avb
This is not exactly a bug, because HTTP_Request neither supports keep-alive nor advertises such support. HTTP_Request explicitly sets "Connection: close" header itself, it is not a good idea to override it.
 [2005-07-13 04:50 UTC] tjerk dot meesters at gmail dot com
Okay, can I just leave it as a change request then? In some circumstances it's more efficient to grab all related content in one go (such as images, style sheets, etc.) over slow connections to minimize network traffic and latency.
 [2005-07-13 06:48 UTC] avb
Fair enough, I'll reopen the request then and change its summary.
 [2006-06-28 11:19 UTC] justinpatrin (Justin Patrin)
Here's a patch which implements keep-alive. In fact, the largest change is simply to respect the content-length header when reading non-chunked data. http://pear.reversefold.com/HTTP_Request/Keep-Alive.patch The changes to _readChunked are probably not needed as, AFAICT content-length and transfer-encoding: chunked are mutually exclusive, but I have included it for completeness. Test script here: http://pear.reversefold.com/HTTP_Request/keepAlive_test.phps This test shows a chunked/non-content-length first request and a content-length second request.
 [2006-06-28 11:46 UTC] justinpatrin (Justin Patrin)
Updated patch: * Removed useless passing of keepAlive to response->process * Switched to _toRead for length check in read()
 [2006-06-28 12:03 UTC] justinpatrin (Justin Patrin)
Fixed windows newlines in patch.
 [2006-06-28 12:30 UTC] justinpatrin (Justin Patrin)
I should also mention that the patch adds notification for connect and disconnect. These can be removed, of course, but they were useful when testing.
 [2006-06-28 12:42 UTC] justinpatrin (Justin Patrin)
Updated patch: * Fixed notice about undefined $err on second+ request * Added check for connection header in response
 [2006-10-24 08:18 UTC] avb (Alexey Borzov)
Keep-alive support added to CVS. Thanks for the provided patch, it served as a base for implementation. Unfortunately it had several problems with conformance to RFC 2068 and RFC 2616 and some unnecessary cahnges, so had to be significantly redone. Also the implementation in CVS allows different instances of HTTP_Request to reuse the same connection.