|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48946 fgets hangs on fsockopen stream
Submitted: 2009-07-16 14:04 UTC Modified: 2009-07-23 22:59 UTC
From: trutas dot ctx at gmail dot com Assigned:
Status: Not a bug Package: IIS related
PHP Version: 5.3.0 OS: Windows Server 2003 x64 IIS6.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: trutas dot ctx at gmail dot com
New email:
PHP Version: OS:


 [2009-07-16 14:04 UTC] trutas dot ctx at gmail dot com
fgets() hangs up to script timeout (60secs) on an opened fsockopen stream.
stream_set_timeout is set for 30 secs - but apparently does nothing.

For now i'll try to work around it using curl and the intranet squid proxy server.

Reproduce code:
$fp = fsockopen("", 443, $errno, $errstr, 30);
if($fp) {
    if(fputs($fp, $headers, strlen($headers))){

      $result = '';
      stream_set_timeout($fp, 30);  //should timeout in 30 secs

      while(!feof($fp)) {
        $result .=fgets($fp, 4096);  //scripts hangs up to script timeout in this line


      print $result;

Expected result:
$result gets printed or error gets thrown out somewhere.

Actual result:
Maximum execution time of 60 seconds exceeded in...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-23 22:59 UTC]
You should actually check if there was timeout in your loop. RTFM at tells:

"When the stream times out, the 'timed_out' key of the array returned by 
stream_get_meta_data() is set to TRUE, although no error/warning is 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 02:01:32 2024 UTC