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

From: Date: Mon, 22 Jun 2015 14:45:23 +0000
Subject: Bug #69900 [NEW]: Commandline input/output weird behaviour
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193761@lists.php.net to get a copy of this message
From: nerdbeere2k at gmail dot com Operating system: Linux, Windows PHP version: 5.5.26 Package: *General Issues Bug Type: Bug Bug description:Commandline input/output weird behaviour Description: ------------ Explaining my whole setup for this would take some time so i'm gonna try to describe it as short as possible. I have a java application where i send some string to php-cli via standard input and read a result string back from standard output to do something else with it. I do this several times, so the php-cli process is getting several commands to work off, and i read the results back. The issue/bug now is that for every fgets call i make the process hangs for 100ms. This worked like a charm until version php-5.5.17 and broke in version php-5.5.18. php-5.6.* seems to have this issue as well. The changelog didn't exactly point towards a change that might've led to this as far as i could see. Especially weird is that it all works fine if i put a "usleep(1)" before the fgets call... I wrote some example breaking down the problem to as few lines as possible: <?php while(!feof(STDIN)){ // usleep(1) <- adding this seems to fix this behaviour... // THIS WILL BLOCK FOR 100ms for every fgets call $s = fgets(STDIN); fwrite(STDOUT, $s); } ?> This script is called from a java application like this (tested on jdk1.8.0_20): public static void main(String[] args) { try { Process p = Runtime.getRuntime().exec("./php-5.5.18/php.exe -f ./php-5.5.18/test.php"); InputStream inputStream = p.getInputStream(); OutputStream outputStream = p.getOutputStream(); byte[] buffer = new byte[1024]; while(p.isAlive()){ outputStream.write("TEST\r\n".getBytes()); outputStream.flush(); int read = inputStream.read(buffer); if(read > -1){ System.out.println(new String(buffer, 0, read)); } } } catch (IOException ex) { ex.printStackTrace(); } } -- Edit bug report at https://bugs.php.net/bug.php?id=69900&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69900&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69900&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69900&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69900&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69900&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69900&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69900&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69900&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69900&r=support Expected behavior: https://bugs.php.net/fix.php?id=69900&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69900&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69900&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69900&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69900&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69900&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69900&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69900&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69900&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69900&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69900&r=mysqlcfg

« previous php.bugs (#193761) next »