Bug #66232 [Opn->Csd]: proc_open: Inconsistent handling of EOFs on pipes
| From: | bukka@php.net | Date: | Tue, 27 Dec 2022 17:02:09 +0000 |
| Subject: | Bug #66232 [Opn->Csd]: proc_open: Inconsistent handling of EOFs on pipes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-243258@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66232&edit=1
ID: 66232
Updated by: bukka@php.net
Reported by: php-bugs at jbeekman dot nl
Summary: proc_open: Inconsistent handling of EOFs on pipes
-Status: Open
+Status: Closed
Type: Bug
Package: Streams related
Operating System: Linux 3.11.4-vhost-blk+ x86_64
PHP Version: 5.5Git-2013-12-04 (Git)
-Assigned To:
+Assigned To: bukka
Block user comment: N
Private report: N
New Comment:
Apology for taking so long to look into this. I have done investigation and debugging of the
provided programs. It comes basically to 2 things as mentioned:
1. EOF handling for pipes - This is a real issue which I created a new issue with all the details:
https://github.com/php/php-src/issues/10171
2. Delay in pipe test (PHP) reading - this is actually and issue in the test (took me some time to
realise that) as it is not the same as C pipetest. Specifically it is using shell (due to $argv
implode). It means that the stdout is not closed for the proc opened program (shell) and it needs
wait for program to finish. If the implode is replaced just by passing $argv (
$p =
proc_open($argv, $descriptorspec, $fd);), then it works in the same way as C example.
So closing this bug as all that needs to be done is described in the new issue. Thanks for reporting
this though.
Previous Comments:
------------------------------------------------------------------------
[2013-12-04 05:17:29] php-bugs at jbeekman dot nl
Here are the test files that the bug tracker would not let me post in the description ("Please
do not SPAM our bug system."). You will have to insert :// in the appropriate places.
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
closewait.c http pastebin.com/utgrkXJM
fifotest.c http pastebin.com/p8R3WsEk
fifotest.php http pastebin.com/bJgCcjpF
pipetest.c http pastebin.com/9Wd2QSLD
pipetest.php http pastebin.com/qRwuZsnx
test.sh http pastebin.com/J8TmXYAG
------------------------------------------------------------------------
[2013-12-04 05:14:34] php-bugs at jbeekman dot nl
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 this bug report at https://bugs.php.net/bug.php?id=66232&edit=1