Bug #69900 [Opn]: Commandline input/output weird behaviour

From: Date: Fri, 26 Jun 2015 20:19:30 +0000
Subject: Bug #69900 [Opn]: Commandline input/output weird behaviour
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193926@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69900&edit=1 ID: 69900 Updated by: ab@php.net Reported by: nerdbeere2k at gmail dot com Summary: Commandline input/output weird behaviour Status: Open Type: Bug Package: *General Issues Operating System: Windows PHP Version: 5.5.26 Block user comment: N Private report: N New Comment: @nerdbeere2k, thanks for the additional input. Ok, i've compiled your java snippet and tested on windows and linux. It clearly shows, that it's a Windows only issue. Were nice if you could confirm that. Also it shows that proc_open isn't involved. Still i suspect pipe handling. But this already gives the direction to debug. Thanks. Previous Comments: ------------------------------------------------------------------------ [2015-06-25 18:50:55] nerdbeere2k at gmail dot com Hello ab, first: thanks again for replying! i must admit i didnt test my last code snippet with Linux, but initially i got a report for my java application which stated that it'd run very slow since upgrading php to 5.6. The environment from that report is Linux, and after i investigated the problem i supposed that this was the source of the problem without specifically testing it on Linux... So i might've been wrong, and if you say so, i probably was and i'm sorry for that! I will take Linux out of the OS list. Concerning proc_open(): i don't think the problem is related to proc_open(), because the java and the php snippet basically do the same thing and the timings and output of both are pretty much equal... I'm also not sure what we're investigating on :) i had hoped maybe someone had an idea what to do! What would you advise? ------------------------------------------------------------------------ [2015-06-25 13:15:46] ab@php.net Thanks for the second code snippet. However it turns the ticket to completely different story. When I run it, i reproduce your findings on Windows, but not on Linux. It might be related on Windows to bugfixes to the proc_open as it previously could block while reading/writing pipes from the child. You initially say it's reproducable on both Linux/Windows and the initial snippet doesn't involve proc_open(). So I'm just not sure what we're investigating on :) Is the last one the code reproducing your exact situation? If not, it's probably worth to workout a snippet not involving proc_open(). Thanks. ------------------------------------------------------------------------ [2015-06-25 07:31:54] nerdbeere2k at gmail dot com Status Open ------------------------------------------------------------------------ [2015-06-24 11:22:07] nerdbeere2k at gmail dot com By the way, if you call the process like this: $process = proc_open(PHP_BINARY.' <?php while(!feof(STDIN)){ $s = fgets(STDIN); fwrite(STDOUT, $s); } ?>', $descriptorspec, $pipes); The problem doesnt occur... just in case someone wonders why i used two separate files. ------------------------------------------------------------------------ [2015-06-24 11:19:08] nerdbeere2k at gmail dot com Hello ab, first thank you very much for looking into this! i tried to simplify this more by removing the java part, and the issue seems to occur here too. I'd agree with you, its probably not a fgets problem but seems to be a general problem with the STDIN/STDOUT stream, but i can't point out what it could be as i am not familiar with the php internals. However, this is the php-only testcase i came up with where the problem occurs: <?php $descriptorspec = array(0 => array("pipe", "r"),1 => array("pipe", "w"), 2 => array("file", "error-output.txt", "a")); $pipes = array(); $process = proc_open(PHP_BINARY.' -f test.php', $descriptorspec, $pipes); if(is_resource($process)){ for($i = 0; $i < 10; $i++){ fwrite($pipes[0], "hello\r\n"); $t0 = microtime(1); $s = fgets($pipes[1]); $t1 = microtime(1); echo $s; echo "fgets() took ", (($t1 - $t0)*1000), "ms\n"; } fclose($pipes[0]); fclose($pipes[1]); proc_close($process); } else die("process creation failed!"); ?> and the test.php file: <?php while(!feof(STDIN)){ $s = fgets(STDIN); fwrite(STDOUT, $s); } ?> The output that php-5.5.26 generates when calling it is as follows: C:\tmp\php_bug_report_69900\>.\php-5.5.26\php.exe -f passproc.php hello fgets() took 100.00491142273ms hello fgets() took 100.00610351562ms hello fgets() took 100.00610351562ms hello fgets() took 100.00586509705ms hello fgets() took 100.00514984131ms hello fgets() took 100.00586509705ms hello fgets() took 100.00610351562ms hello fgets() took 100.00491142273ms hello fgets() took 100.00610351562ms hello fgets() took 100.00586509705ms The output with php-5.5.17 is as follows: C:\tmp\php_bug_report_69900\>.\php-5.5.17\php.exe -f passproc.php hello fgets() took 19.001007080078ms hello fgets() took 0ms hello fgets() took 0ms hello fgets() took 0ms hello fgets() took 0ms hello fgets() took 0ms hello fgets() took 0ms hello fgets() took 0ms hello fgets() took 0ms hello fgets() took 0ms Hope this helps! Thanks again! ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=69900 -- Edit this bug report at https://bugs.php.net/bug.php?id=69900&edit=1

« previous php.bugs (#193926) next »