|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76342 file_get_contents waits twice specified timeout
Submitted: 2018-05-15 12:07 UTC Modified: -
Avg. Score:3.8 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: hadrien dot sibboni at tagpay dot fr Assigned:
Status: Closed Package: Streams related
PHP Version: Irrelevant OS: Debian 7, Windows
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: hadrien dot sibboni at tagpay dot fr
New email:
PHP Version: OS:


 [2018-05-15 12:07 UTC] hadrien dot sibboni at tagpay dot fr

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.4/Debian 9.4
5.6.23/Debian 7.11

Test script:
client code :
$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:

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
duration: 8.0089149475098

If timeout < sleepTime < 2*timeout : will wait ~sleepTime, and still fail.


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-29 22:43 UTC] calvet dot thomas at gmail dot com
The following pull request has been associated:

Patch Name: Fix #76342: file_get_contents waits twice specified timeout
On GitHub:
 [2019-09-17 13:44 UTC]
Automatic comment on behalf of
Log: Fix #76342: file_get_contents waits twice specified timeout
 [2019-09-17 13:44 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 05:01:28 2024 UTC