Bug #66232 [NEW]: proc_open: Inconsistent handling of EOFs on pipes
| From: | php-bugs at jbeekman dot nl | Date: | Wed, 04 Dec 2013 05:14:35 +0000 |
| Subject: | Bug #66232 [NEW]: proc_open: Inconsistent handling of EOFs on pipes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-183118@lists.php.net to get a copy of this message | ||
From: php-bugs at jbeekman dot nl
Operating system: Linux 3.11.4-vhost-blk+ x86_64
PHP version: 5.5Git-2013-12-04 (Git)
Package: Streams related
Bug Type: Bug
Bug description:proc_open: Inconsistent handling of EOFs on pipes
Description:
------------
When a program executed with proc_open closes an output pipe, PHP
sometimes incorrectly reports that the stream has not reached EOF and at
other times it's stuck in a blocking read.
Attached are 5 test programs and a test script:
* The closewait program is a test program that writes a specified number
of bytes to STDOUT, closes STDOUT, and sleeps for a specified time.
* The fifotest* programs are used to test the operation of named pipes
(FIFOs). The C and PHP version are very similar. just opening a
specified file and reading from it in 64-byte chunks until error/EOF.
* The pipetest* programs are used to test the operation of unnamed pipes
(pipes). The C version uses pipe() to create the pipe and fork() to give
one end to a child process. The PHP version uses proc_open() to do the
same. Both programs use the same logic as the fifotest* programs to read
from the pipe.
* The test.sh script compiles the C programs and runs the C and PHP
programs with different parameters.
From the tests, you can see that the FIFOs work the same in both C and
PHP, but that the pipe has some erratic behavior. In one case it exits
after reading all the data from the pipe, but does not indicate EOF. In
two other cases it blocks after reading all the data from the pipe until
the child process exits.
From `man 7 pipe': "[I/O on pipes and FIFOs] The only difference between
pipes and FIFOs is the manner in which they are created and opened. Once
these tasks have been accomplished, I/O on pipes and FIFOs has exactly
the same semantics."
There is no posix_pipe() (see bug #60896), so I can't test whether there
is an issue with pipes in general or just with proc_open().
Test script:
---------------
git commit 00a7b1ff (branch PHP-5.5 as of 2013-12-3 16:36:07 PST)
Configure Command: './configure' '--disable-all' '--disable-cgi'
'--enable-cli'
Download all of the following and save them under the specified name in
the same folder and then: chmod ugo+x test.sh; ./test.sh
** unable to post links because of bugs.php.net spam detection **
Expected result:
----------------
===>FIFO test (C)
n: 63 EOF: 1
n: 64 n: 0 EOF: 1
n: 64 n: 1 EOF: 1
===>FIFO test (PHP)
n: 63 EOF: 1
n: 64 n: 0 EOF: 1
n: 64 n: 1 EOF: 1
===>pipe test (C)
n: 63 EOF: 1
n: 64 n: 0 EOF: 1
n: 64 n: 1 EOF: 1
===>pipe test (PHP)
n: 63 EOF: 1
n: 64 n: 0 EOF: 1
n: 64 n: 1 EOF: 1
real less than 1
user irrelevant
sys irrelevant
Actual result:
--------------
===>FIFO test (C)
n: 63 EOF: 1
n: 64 n: 0 EOF: 1
n: 64 n: 1 EOF: 1
===>FIFO test (PHP)
n: 63 EOF: 1
n: 64 n: 0 EOF: 1
n: 64 n: 1 EOF: 1
===>pipe test (C)
n: 63 EOF: 1
n: 64 n: 0 EOF: 1
n: 64 n: 1 EOF: 1
===>pipe test (PHP)
n: 63 EOF: 0
n: 64 n: 0 EOF: 1
n: 64 n: 1 EOF: 1
real 2.13
user 0.04
sys 0.06
--
Edit bug report at https://bugs.php.net/bug.php?id=66232&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66232&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66232&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66232&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66232&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66232&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66232&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66232&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66232&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66232&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66232&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66232&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66232&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66232&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66232&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66232&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66232&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66232&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66232&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66232&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66232&r=mysqlcfg