Bug #62697 [Com]: stream_get_line hangs
| From: | brandon dot landry at dvusd dot org | Date: | Tue, 31 Jul 2012 17:39:40 +0000 |
| Subject: | Bug #62697 [Com]: stream_get_line hangs | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-172353@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62697&edit=1
ID: 62697
Comment by: brandon dot landry at dvusd dot org
Reported by: brandon dot landry at dvusd dot org
Summary: stream_get_line hangs
Status: Feedback
Type: Bug
Package: Filesystem function related
Operating System: suse
PHP Version: 5.3.15
Block user comment: N
Private report: N
New Comment:
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"
Previous Comments:
------------------------------------------------------------------------
[2012-07-31 16:47:22] 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 15:27:26] 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-30 15:57:01] 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));
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62697&edit=1