Bug #69963 [Asn]: fgets reads EOF if there is nothing on the PIPE to read for a short period

From: Date: Tue, 30 Jun 2015 13:27:19 +0000
Subject: Bug #69963 [Asn]: fgets reads EOF if there is nothing on the PIPE to read for a short period
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194014@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69963&edit=1

 ID:                 69963
 User updated by:    poonam dot chawla at mathworks dot com
 Reported by:        poonam dot chawla at mathworks dot com
 Summary:            fgets reads EOF if there is nothing on the PIPE to
                     read for a short period
 Status:             Assigned
 Type:               Bug
 Package:            Streams related
 Operating System:   Windows
 PHP Version:        5.6.10
 Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

My apologies. That is correct.


Previous Comments:
------------------------------------------------------------------------
[2015-06-30 11:30:05] ab@php.net

@poonam, you obviously meant feof, not fgets?

Thanks.

------------------------------------------------------------------------
[2015-06-29 21:17:42] poonam dot chawla at mathworks dot com

Hi,

Thanks for an early response. It is a WINDOWS ONLY issue but unfortunately not the same one.

69900 : The issue/bug is that for every fgets call process hangs for 100ms.
However, in the issue I am experiencing there is no delay/hang on fgets.

Thanks,
Poonam

------------------------------------------------------------------------
[2015-06-29 20:57:34] cmb@php.net

If that is a Windows only issue, it might be somehow related to
bug #69900.

------------------------------------------------------------------------
[2015-06-29 20:21:01] poonam dot chawla at mathworks dot com

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 this bug report at https://bugs.php.net/bug.php?id=69963&edit=1


Thread (9 messages)

« previous php.bugs (#194014) next »