php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65634 HTTP wrapper is very slow with protocol_version 1.1
Submitted: 2013-09-08 16:27 UTC Modified: 2013-09-11 21:17 UTC
From: butesa at freenet dot de Assigned: aharvey (profile)
Status: Closed Package: HTTP related
PHP Version: 5.5.3 OS: Ubuntu 12.04 x64
Private report: No CVE-ID: None
 [2013-09-08 16:27 UTC] butesa at freenet dot de
Description:
------------
Loading a website with the http wrapper takes very long if protocol_version is set to 1.1. The time it takes depends on the timeout. On some servers the problem doesn't occur.

I tested also on Ubuntu 10.04 (PHP 5.3.2-1ubuntu4.19) and Ubuntu 12.04 (PHP 5.3.10-1ubuntu3.7), both 64bit.

Test script:
---------------
<?php
$url = 'http://www.google.de/intl/de/policies/?fg=1';
foreach(array(1.0,1.1) as $proto)
{
	for ($timeout = 1; $timeout < 60; $timeout+=10)
	{
		$st = microtime(true);
		$opt = array(
			'http' => array(
				'timeout' => $timeout,
				'protocol_version' => $proto,
				),
			);
		$context = stream_context_create($opt);
		$content = file_get_contents($url,false,$context);
		printf("%2d %.1f %f %s\n", $timeout, $proto, microtime(true) - $st, md5($content));
	}
}
?>

Expected result:
----------------
The request takes the same time, no matter what timeout and protocol_version is set.

Actual result:
--------------
Output of the test script:
For $url='http://www.google.de/intl/de/policies/?fg=1':
 1 1.0 0.279102 60bf7bc72d2a06b337c8a8464e0f9e66
11 1.0 0.277956 60bf7bc72d2a06b337c8a8464e0f9e66
21 1.0 0.283753 60bf7bc72d2a06b337c8a8464e0f9e66
31 1.0 0.285862 60bf7bc72d2a06b337c8a8464e0f9e66
41 1.0 0.277894 60bf7bc72d2a06b337c8a8464e0f9e66
51 1.0 0.285653 60bf7bc72d2a06b337c8a8464e0f9e66
 1 1.1 2.284301 60bf7bc72d2a06b337c8a8464e0f9e66
11 1.1 22.305424 60bf7bc72d2a06b337c8a8464e0f9e66
21 1.1 42.309270 60bf7bc72d2a06b337c8a8464e0f9e66
31 1.1 62.355997 60bf7bc72d2a06b337c8a8464e0f9e66
41 1.1 82.360794 60bf7bc72d2a06b337c8a8464e0f9e66
51 1.1 102.379933 60bf7bc72d2a06b337c8a8464e0f9e66

For $url='http://www.example.com':
 1 1.0 0.491382 09b9c392dc1f6e914cea287cb6be34b0
11 1.0 0.426191 09b9c392dc1f6e914cea287cb6be34b0
21 1.0 0.428513 09b9c392dc1f6e914cea287cb6be34b0
31 1.0 0.423852 09b9c392dc1f6e914cea287cb6be34b0
41 1.0 0.423751 09b9c392dc1f6e914cea287cb6be34b0
51 1.0 0.431590 09b9c392dc1f6e914cea287cb6be34b0
 1 1.1 1.420486 09b9c392dc1f6e914cea287cb6be34b0
11 1.1 6.143113 09b9c392dc1f6e914cea287cb6be34b0
21 1.1 5.994384 09b9c392dc1f6e914cea287cb6be34b0
31 1.1 5.991940 09b9c392dc1f6e914cea287cb6be34b0
41 1.1 6.012121 09b9c392dc1f6e914cea287cb6be34b0
51 1.1 6.007920 09b9c392dc1f6e914cea287cb6be34b0

For $url='http://www.php.net':
 1 1.0 1.673016 2dcc6fe85b335205a35d9980a9095735
11 1.0 1.935555 2dcc6fe85b335205a35d9980a9095735
21 1.0 1.648235 2dcc6fe85b335205a35d9980a9095735
31 1.0 1.637566 2dcc6fe85b335205a35d9980a9095735
41 1.0 1.633473 2dcc6fe85b335205a35d9980a9095735
51 1.0 1.718051 2dcc6fe85b335205a35d9980a9095735
 1 1.1 1.647803 2dcc6fe85b335205a35d9980a9095735
11 1.1 1.863799 2dcc6fe85b335205a35d9980a9095735
21 1.1 1.673567 2dcc6fe85b335205a35d9980a9095735
31 1.1 1.651704 2dcc6fe85b335205a35d9980a9095735
41 1.1 1.657976 2dcc6fe85b335205a35d9980a9095735
51 1.1 1.635651 2dcc6fe85b335205a35d9980a9095735

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-09 23:03 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2013-09-09 23:03 UTC] aharvey@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

www.google.de responds with a keep-alive connection when a HTTP/1.1 request is 
made and no Connection request header is included, which is valid in RFC 2616. 
Sending a "Connection: close" request header restores the 1.0 behaviour.
 [2013-09-09 23:52 UTC] butesa at freenet dot de
I don't see how it can be not a bug if a http request takes 100 seconds.
If the server uses connection: keep-alive, then the client has to close the connection if it doesn't want to make any further requests.
 [2013-09-10 19:43 UTC] butesa at freenet dot de
I looked into RFC 2616 today. It says:
HTTP/1.1 applications that do not support persistent connections MUST include the "close" connection option in every message.

Obviously, the HTTP wrapper can't handle persistent connections correctly. So it should automatically add a Connection: close header when protocol_version is set to 1.1.
 [2013-09-11 20:30 UTC] aharvey@php.net
-Status: Not a bug +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2013-09-11 20:30 UTC] aharvey@php.net
Fair point. Let me see if we can send a Connection: close request header by 
default and allow overriding via the headers context option if the user wants it 
for some reason.
 [2013-09-11 21:17 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2013-09-11 21:17 UTC] aharvey@php.net
Implemented on master:
https://github.com/php/php-src/commit/8983a38d5130c11bd96643dfa2b2f1393ac5969d

I don't think this is a good candidate for 5.4 or 5.5: it's debatable whether 
this is a bug fix, and it does subtly change PHP's behaviour. I'd be surprised if 
it broke any code, but it should be something users have to test, and putting it 
in the next version should ensure that.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC