Bug #69963 [NEW]: fgets reads EOF if there is nothing on the PIPE to read for a short period
| From: | poonam dot chawla at mathworks dot com | Date: | Mon, 29 Jun 2015 20:21:02 +0000 |
| Subject: | Bug #69963 [NEW]: fgets reads EOF if there is nothing on the PIPE to read for a short period | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193999@lists.php.net to get a copy of this message | ||
From: poonam dot chawla at mathworks dot com
Operating system: Windows
PHP version: 5.6.10
Package: Streams related
Bug Type: Bug
Bug description:fgets reads EOF if there is nothing on the PIPE to read for a short period
Description:
------------
I am using PHP to read from STDIN and write to a log file. The PHP
process is spawned by another process (for the example sake, I am
attaching a python script that spawns a new PHP process).
I observed that if there is nothing to read on the STDIN for a short
period of time, PHP behaves unexpectedly (reads EOF and exits).It was
interesting to find out that PHP 5.4 exhibhits the correct behavior,
however both PHP 5.5 and 5.6 behave unexpectedly.
Test script:
---------------
PHP:
<?php
$in = fopen("php://stdin", "rb");
$out = fopen('C:/Users/pchawla/php_test/log_file.txt', 'w');
while ( ! feof($in) ) {
$line = fgets($in);
fwrite($out, $line);
}
?>
import subprocess
import sys
Python:
import subprocess
import sys
def log():
proc = subprocess.Popen(['php',
'C:/Users/pchawla/php_test/log_handler.php'], stdin=subprocess.PIPE)
while True:
line = sys.stdin.readline();
proc.stdin.write(line)
if __name__ == "__main__":
log()
Expected result:
----------------
fgets() should return FALSE only when there is an error or it reads EOF
from the PIPE.
Actual result:
--------------
fgets() returns FALSE when there is nothing to read from the PIPE for a
short period of time (~20 seconds).
--
Edit bug report at https://bugs.php.net/bug.php?id=69963&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69963&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69963&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69963&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69963&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69963&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69963&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69963&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69963&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69963&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69963&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69963&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69963&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69963&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69963&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69963&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69963&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69963&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69963&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69963&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69963&r=mysqlcfg