|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-03-24 15:52 UTC] roborg at gmail dot com
Description:
------------
Valid modes for pipes are "r" and "w" according to the docs.
Though a comment in the docs suggests using "a" for STDERR on Windows, I believe this may be outdated.
Modes other than "r" and "w" (and possibly "a"?) should trigger an error, but are silently ignored and the pipe just doesn't work properly.
Test script:
---------------
$descriptors = array(
array('pipe', 'x'),
array('pipe', 'y'),
array('pipe', 'z'),
);
$process = proc_open('ls', $descriptors, $pipes);
proc_close($process);
Expected result:
----------------
Error: proc_open(): x is not a valid descriptor mode
Actual result:
--------------
(nothing)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 17:00:02 2025 UTC |
in proc_open: if (strncmp(Z_STRVAL_PP(zmode), "w", 1) != 0) { descriptors[ndesc].parentend = newpipe[1]; descriptors[ndesc].childend = newpipe[0]; descriptors[ndesc].mode |= DESC_PARENT_MODE_WRITE; } else { descriptors[ndesc].parentend = newpipe[0]; descriptors[ndesc].childend = newpipe[1]; } so, it's very clear why no notice was raised(assume "r" by default). considering bc issue, and not very helpful notices.... maybe change to a doc issue is better.I've tested the script below with these results (sorry, I can't run these on the same OS): PHP: 5.3.5 OS: Win XP Mode: w Result: Script hangs PHP: 5.3.5 OS: Win XP Mode: a Result: Empty string PHP: 5.5.13 OS: Win 7 Mode: w Result: string 'x.......' PHP: 5.5.13 OS: Win 7 Mode: a Result: Empty string So the behavior has changed somewhat between 5.3 and 5.5, but not in the way I thought... It looks like the "a" mode never actually worked (as the output was empty), but just tricked PHP/Windows into not hanging. I still think failing silently is a really bad thing though. <?php $descriptors = array( array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'), // This one changes between 'a' and 'w' ); $process = proc_open('c:\php\php.exe -r "$f = fopen(\'php://stderr\', \'w+\');fwrite($f, str_repeat(\'x\' . chr(10), 2048));', $descriptors, $pipes); var_dump(stream_get_contents($pipes[1])); var_dump(stream_get_contents($pipes[2])); proc_close($process);