Edit report at https://bugs.php.net/bug.php?id=60131&edit=1
ID: 60131 Patch added by: cataphr...@php.net Reported by: frederic dot hardy at mageekbox dot net Summary: fopen('php://stdout'...) redirect all posterious echo to /dev/null Status: Wont fix Type: Bug Package: Streams related Operating System: Mac OS Snow Leopard PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: The following patch has been added/updated: Patch Name: bug60131.diff Revision: 1319944441 URL: https://bugs.php.net/patch-display.php?bug=60131&patch=bug60131.diff&revision=1319944441 Previous Comments: ------------------------------------------------------------------------ [2011-10-30 03:09:23] cataphr...@php.net Won't fix since some people rely on this behavior. What happens is the first time you fopen stdout, the file descriptor 1 is not duped and exposed with a stream, instead the stdlib FILE* is exposed through a stream. When the stream is closed, the FILE* is closed too, potentially also closing stdout, i.e., a close(1) syscall (which is what happens in your case â since you don't assign the return of fopen, the stream is immediately destroyed). Turns out some people use this technique to close the standard file descriptors and open others (and AFAIK there's no other way to do it in PHP). ------------------------------------------------------------------------ [2011-10-25 14:24:53] frederic dot hardy at mageekbox dot net Description: ------------ If fopen('php://stdout', ...) is used in a php processus open with proc_open(), all posterious call to echo or print seems to be redirected to /dev/null. Test script: --------------- <?php $descriptors = array( 0 => array("pipe", "r"), 1 => array("pipe", "w") ); $php = proc_open('php', $descriptors, $pipes); stream_set_blocking($pipes[1], 0); fwrite($pipes[0], '<?php echo \'foo\'; fopen(\'php://stdout\', \'w\'); echo \'bar\'; ?>'); fclose($pipes[0]); $null = null; $select = array($pipes[1]); while (feof($pipes[1]) === false) { if (stream_select($select, $null, $null, null)) { var_dump(stream_get_contents($pipes[1])); } } Expected result: ---------------- foobar Actual result: -------------- foo ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60131&edit=1