php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70361 HTTP stream wrapper doesn't close keep-alive connections
Submitted: 2015-08-25 18:04 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: me at kelunik dot com Assigned:
Status: Closed Package: Streams related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: me at kelunik dot com
New email:
PHP Version: OS:

 

 [2015-08-25 18:04 UTC] me at kelunik dot com
Description:
------------
Downloading a file with file_get_contents("http://example.com/example.json"); defaults to using HTTP/1.0. RFC compliant servers should respond with a HTTP/1.1 in such a case if they support HTTP/1.1. Some servers initiate a keep-alive connection in that case, resulting a client hang, because PHP waits until the connection is closed instead of relying on the Content-Length header.

This behavior should be fixed in two ways: (1) Always send "Connection: close" – even for HTTP/1.0 requests – and (2) use Content-Length to determine the end of a response and close the connection then.

My attached patch only fixes the first point.

Information regarding relevant spec: http://serverfault.com/a/442978/217277
file_get_contents behavior description: http://stackoverflow.com/a/4240241/2373138


Patches

fix-http-connection-close (last revision 2015-08-25 18:05 UTC by me at kelunik dot com)

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-25 22:05 UTC] me at kelunik dot com
Patch is outdated, PR contains test fixes and NEWS entry.
 [2015-09-04 14:32 UTC] bwoebi@php.net
Automatic comment on behalf of me@kelunik.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4b1dff6f438f84f7694df701b68744edbdd86153
Log: Fix #70361: HTTP stream wrapper doesn't close keep-alive connections
 [2015-09-04 14:32 UTC] bwoebi@php.net
-Status: Open +Status: Closed
 [2015-09-04 14:36 UTC] bwoebi@php.net
Automatic comment on behalf of me@kelunik.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4b1dff6f438f84f7694df701b68744edbdd86153
Log: Fix #70361: HTTP stream wrapper doesn't close keep-alive connections
 [2015-09-15 12:13 UTC] ab@php.net
Automatic comment on behalf of me@kelunik.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4b1dff6f438f84f7694df701b68744edbdd86153
Log: Fix #70361: HTTP stream wrapper doesn't close keep-alive connections
 [2016-03-03 19:13 UTC] divinity76 at gmail dot com
note that "fixing" this may actually break code that communicate with dodgy http servers sending the wrong content-length header. the original code will read all bytes until the connection closes, completely disregarding content-length (which, with keep-alive connections, can have huge performance penalties), thus still working if the content-header is incorrect :p not saying this isn't a good thing, just that it IS a edge-case backward-incompatible change
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC