ID: 25575
Updated by: [EMAIL PROTECTED]
Reported By: bill at baghead dot co dot uk
-Status: Open
+Status: Feedback
Bug Type: Sockets related
Operating System: Redhat 9
PHP Version: 4CVS-2003-09-17 (stable)
New Comment:
The default mode for streams is blocking mode, so you shouldn't need to
call this function at all.
Is xinetd setting it to non-blocking before the script starts?
It does sound like you have a bug there, I just thought you might like
to try a workaround until it gets fixed.
Previous Comments:
------------------------------------------------------------------------
[2003-09-17 11:13:43] bill at baghead dot co dot uk
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 this bug report at http://bugs.php.net/?id=25575&edit=1