Bug #76342 [NEW]: file_get_contents waits twice specified timeout
| From: | hadrien dot sibboni at tagpay dot fr | Date: | Tue, 15 May 2018 12:07:34 +0000 |
| Subject: | Bug #76342 [NEW]: file_get_contents waits twice specified timeout | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215261@lists.php.net to get a copy of this message | ||
From: hadrien dot sibboni at tagpay dot fr
Operating system: Debian 7, Windows
PHP version: Irrelevant
Package: Streams related
Bug Type: Bug
Bug description:file_get_contents waits twice specified timeout
Description:
------------
Hello,
I am using file_get_contents to get a url on a web server (apache 2.4).
I am using a stream context to specify the timeout.
1) The script will wait as much as twice the timeout specified.
2) If it gets an anwser between the specified timeout and twice this
timeout, although it waited for the answer, it will still fail with a
warning.
This was done on php versions :
7.2.3/Windows,
7.2.4/Debian 9.4
5.6.23/Debian 7.11
Test script:
---------------
client code :
<?php
$timeout = 4;
$context_options = array
(
'http' => array
(
'timeout' => $timeout,
'method' => 'GET',
),
);
$context = stream_context_create($context_options);
$start = microtime(true);
$content = file_get_contents('http://localhost/test.php', false,
$context) . PHP_EOL;
$end = microtime(true);
echo 'content: ' . $content;
echo 'duration: ' . ($end - $start);
server code:
<?php
sleep(10);
exit();
Expected result:
----------------
The script should only wait the timeout specified in the stream
context.
Actual result:
--------------
If the sleepTime > 2*timeout : in given code : 10 > 2*4
Output is :
PHP Warning: file_get_contents(http://localhost/test.php): failed to
open stream: HTTP request failed! in /path/testFile.php on line 17
content:
duration: 8.0089149475098
If timeout < sleepTime < 2*timeout : will wait ~sleepTime, and still
fail.
--
Edit bug report at https://bugs.php.net/bug.php?id=76342&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76342&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76342&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76342&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76342&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76342&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76342&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76342&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76342&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76342&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76342&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76342&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76342&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76342&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76342&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76342&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76342&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76342&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76342&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76342&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76342&r=mysqlcfg