php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48280 http stream timeout is doubled
Submitted: 2009-05-14 11:59 UTC Modified: 2011-08-30 11:48 UTC
Votes:5
Avg. Score:3.4 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at bouchery dot fr Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.2SVN-2009-12-22 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2009-05-14 11:59 UTC] php at bouchery dot fr
Description:
------------
When I perform a HTTP timeout using "stream_context_create", "stream_set_timeout" or "default_socket_timeout", timeout is doubled.

I did it on : 
- Windows XP SP2 + PHP-Cli 5.1.6
- Windows XP SP2 + PHP-Cli 5.2.9-2
- Debian 5 + PHP 5.2.0-8+etch13 (cli)

Reproduce code:
---------------
<?php
$time = time();

// sleep-flush.php flush a text before sleeping 20 seconds
$f = @fopen('http://localhost/sleep-flush.php', 'r');
if( $f !== false ) {
	stream_set_timeout($f, 2);
	$content = stream_get_contents( $f );
	fclose($f);
}
echo 'Code #1: Duration = ', (time() - $time), "\n";

$context = stream_context_create(array('http' => array('timeout' => 3)));

$time = time();
// sleep do not flush text before sleeping 20 seconds
$f = @fopen('http://localhost/sleep.php', 'r', false, $context);
if( $f !== false ) {
	$content = stream_get_contents( $f );
	fclose($f);
}
echo 'Code #2: Duration = ', (time() - $time), "\n";

ini_set('default_socket_timeout', '4');

$time = time();
// sleep do not flush text before sleeping 20 seconds
$f = @fopen('http://localhost/sleep.php', 'r');
if( $f !== false ) {
	$content = stream_get_contents( $f );
	fclose($f);
}
echo 'Code #3: Duration = ', (time() - $time), "\n";

?>

Expected result:
----------------
Code #1: Duration = 2
Code #2: Duration = 3
Code #3: Duration = 4


Actual result:
--------------
Code #1: Duration = 4
Code #2: Duration = 6
Code #3: Duration = 8


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-20 12:59 UTC] jani@php.net
And where are the sources for those server side scripts?
 [2009-05-20 13:29 UTC] php at bouchery dot fr
I did it on localhost and on a remote machine:

sleep-flush.php
<?php
echo 'start';
flush();
sleep(20);
echo 'sleep';
?>

sleep.php
<?php
sleep(20);
echo 'sleep';
?>
 [2009-12-22 10:51 UTC] php at bouchery dot fr
No, result is already : 
Code #1: Duration = 4
Code #2: Duration = 6
Code #3: Duration = 8
 [2011-05-05 15:35 UTC] james dot mk dot green at gmail dot com
This remains a bug in 5.3.5 on Linux. Setting the timeout to 2 results in a 4s timeout, setting it to 4 results in an 8s timeout.
 [2011-08-30 11:48 UTC] bjori@php.net
-Status: Open +Status: Bogus
 [2011-08-30 11:48 UTC] bjori@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

the value is used both for connection timeout, and then again for read timeout.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC