From:             bill at baghead dot co dot uk
Operating system: Redhat 9
PHP version:      4CVS-2003-09-17 (stable)
PHP Bug Type:     Sockets related
Bug description:  stream_set_blocking with STDIN doesnt block

Description:
------------
Hi,

When using xinetd with a php script - then using php to read from the
"socket" with STDIN / STDOUT, as thats how xinetd translates sockets. I
find that setting blocking on the socket like the code below, I find the
while loops and uses all my cpu time - whereas the fread should block, and
wait till it gets something..

If I uncomment the sleep line - it drops down the cpu usage, but I would
rather have the blocking working.

The process function processes the data, and is irrelevant here.

PHP Was compiled with:
./configure --enable-cli --with-sockets --with-openssl --with-curl
--enable-pcntl --enable-sigchild --with-mysql --enable-sockets

Made with:
 C_INCLUDE_PATH=/usr/kerberos/include make

Version:
PHP 4.3.4-dev (cli) (built: Sep 17 2003 16:04:24)



Reproduce code:
---------------
<?php
set_time_limit (0);
ob_implicit_flush ();
stream_set_blocking(STDIN,TRUE);
$read = array(STDIN);

while (true) {
        $buf = fread(STDIN,128);
        //if ($buf == "") { sleep(1); }
        process($buf);
        unset($buf);
}
?>

Expected result:
----------------
For the fread to block and wait for input, rather than return immediately.

Actual result:
--------------
The fread returns (even with no data), and loops.

-- 
Edit bug report at http://bugs.php.net/?id=25575&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25575&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25575&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25575&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25575&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25575&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25575&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25575&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25575&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25575&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25575&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25575&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25575&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25575&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25575&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25575&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25575&r=float

Reply via email to