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 16:31 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  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 43 - 10 = ?

 
 [2005-07-12 16: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 06: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 09: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 11:48 UTC] avb
Fair enough, I'll reopen the request then and change its summary.
 [2006-06-28 16: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 16: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 17:03 UTC] justinpatrin (Justin Patrin)
Fixed windows newlines in patch.
 [2006-06-28 17: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 17: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 13: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.