php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62697 stream_get_line hangs
Submitted: 2012-07-30 15:57 UTC Modified: 2012-09-01 22:27 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: brandon dot landry at dvusd dot org Assigned:
Status: Open Package: Filesystem function related
PHP Version: 5.3.15 OS: suse
Private report: No CVE-ID: None
 [2012-07-30 15:57 UTC] brandon dot landry at dvusd dot org
Description:
------------
In php 5.3.11 there was some change made to stream_get_line which causes this test 
script to hang (it still hangs on the latest version from 5.3 and 5.4 branches).  
In  the changelog for that version it says stream_get_line was changed to be more 
in line with fgets ... Now if you replace stream_get_line with fgets the script 
does run seemingly correctly ... The only reason I am reporting this is, if the 
function was changed to be more in line with fgets, and fgets works but 
stream_get_line does not, ... is this a bug or something I am missing.


Test script:
---------------
<?php

$descSpec = array(
    array('pipe','r'),  // stdin
    array('pipe','w'),  // stdout
    array('pipe','w')   // stderr
);
$proc = proc_open('bash', $descSpec, $pipes,'/tmp',array());
if(!is_resource($proc)){
    throw new Exception("Could not open bash process");
}
$stdin  = &$pipes[0];
$stdout = &$pipes[1];
$stderr = &$pipes[2];

stream_set_blocking($stdout,0);
stream_set_blocking($stderr,0);

fwrite($stdin, "pwd\n");
fflush($stdin);

$write = null;
$except = null;
$stdoutArr  = array($stdout);
$rv = stream_select($stdoutArr,$write,$except,1);
$strIn = stream_get_line($stdout,4096);
var_export(array('streamSelect_returnVal'=>$rv,'stdout_strRead'=>$strIn));


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-31 15:27 UTC] laruence@php.net
I can not reproduce this on linux, (after replace the stream_get_line to fgets);


could you please provide a reproducable script?
 [2012-07-31 15:27 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2012-07-31 16:47 UTC] brandon dot landry at dvusd dot org
I apologize, the script does not hang (that was the effect in the production 
code I extracted this snipit from) , this script simply does not return the 
correct data.  I copied the test script i submitted into test.php and ran these 
2 tests on a sles linux 11.2 install.
Here is the result of the tests:

webdevel@DVP-VM src $ php ./test.php
array (
  'streamSelect_returnVal' => 1,
  'stdout_strRead' => '/tmp
',
)webdevel@DVP-VM src $ vi test.php
webdevel@DVP-VM src $ # changed fgets to stream_get_line
webdevel@DVP-VM src $ php ./test.php
array (
  'streamSelect_returnVal' => 1,
  'stdout_strRead' => false,
webdevel@DVP-VM src $ cat /etc/SuSE-release
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 2
webdevel@DVP-VM src $ uname -a
Linux DVP-VM 3.0.34-0.7-default #1 SMP Tue Jun 19 09:56:30 UTC 2012 (fbfc70c) 
x86_64 x86_64 x86_64 GNU/Linux

I've tried on openSuse and Novell's Suse with the same results, unfortunately 
we're tied to suse for our environment here, but I could try installing an 
ubuntu vm for testing if required.
 [2012-07-31 17:39 UTC] brandon dot landry at dvusd dot org
Ok, So i tested against Ubuntu 12.04 same result, results follow:


root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# ./php -v
PHP 5.3.15 (cli) (built: Jul 31 2012 10:34:56)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# php -v
PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# vi ~/test.php
root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# ./php ~/test.php
array (
  'streamSelect_returnVal' => 1,
  'stdout_strRead' => false,
)root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# php ~/test.php
array (
  'streamSelect_returnVal' => 1,
  'stdout_strRead' => '/tmp
',
)root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# # about to change 
stream_get_line to fgets
root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# vi /root/test.php
root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# ./php ~/test.php
array (
  'streamSelect_returnVal' => 1,
  'stdout_strRead' => '/tmp
',
)root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# php ~/test.php
array (
  'streamSelect_returnVal' => 1,
  'stdout_strRead' => '/tmp
',
)root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# uname -a
Linux brandon-ubuntu 3.2.0-27-generic #43-Ubuntu SMP Fri Jul 6 14:25:57 UTC 2012 
x86_64 x86_64 x86_64 GNU/Linux
root@brandon-ubuntu:~/php/php-5.3.15/sapi/cli# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
 [2012-09-01 22:27 UTC] cataphract@php.net
I can't reproduce too. It returns false, it does not block (and you can get the same behavior as fgets() by specifying "\n" as a delimiter in the last parameter).

I'm leaving this opened has a doc bug because returning false in this situation is not explicitly documented:

1073        /* return with error if the delimiter string (if any) was not found, we
1074         * could not completely fill the read buffer with maxlen bytes and we
1075         * don't know we've reached end of file. Added with non-blocking streams
1076         * in mind, where this situation is frequent */

So if the stream is temporarily out of data, we haven't read maxlen bytes and the feof marker is not flipped, it returns false.
 [2012-09-01 22:27 UTC] cataphract@php.net
-Status: Feedback +Status: Open -Type: Bug +Type: Documentation Problem
 [2012-09-04 20:14 UTC] brandon dot landry at dvusd dot org
>>It returns false, it does not block
Yes, I incorrectly stated it hung, instead it returns false, returning false is 
the issue(as stated in my first comment, which I corrected myself there).  Prior 
to 5.3.11 it didn't return false, it returned the contents of 
the buffer.  Should the behavior have changed if it was intended to function more 
like a function who's functionality did not change?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 18:01:30 2024 UTC