From: djgrrr at gmail dot com
Operating system: Linux 2.6
PHP version: 4.4.2
PHP Bug Type: Streams related
Bug description: fwrite buffers when writing to socket
Description:
------------
when sending text through a socket, opened with fsockopen() or
stream_socket_client() (in the case of php5) if you send more than
aproximately 10 lines (with \r\n or \n as the EOL) all at once, it will
begin to buffer after the 10 lines are sent to be writen with fwrite; It
does not matter what the blocking setting, or the stream timeout setting
is set at. The script will not block and will continue executing like
normal, reading from the socket is instant and never buffers, so
basically, you have a socket that can recive and process data extreamly
fast, but is not able to write back to the stream at the same speed.
Reproduce code:
---------------
<?php
$s = fsockopen("localhost",23);
stream_set_timeout($s,0,95000);
stream_set_blocking($s,false);
stream_set_write_buffer($s,0);
$i = 0;
while ($i < 1000) {
$i++;
if (feof($s))
break;
$in=trim(fgets($s,4096));
if ($in != "")
{
usleep(5000);
// do some processing here
}
fwrite($s,"hello $i\r\n");
}
?>
Expected result:
----------------
i expect it to write "hello #\r\n" where # is 1-1000 to the socket very
fast (at least once every 0.1 seconds)
Actual result:
--------------
it will write around 10 lines to the socket very quickly, then will start
to buffer at around 1 line per second, which in the case where you need
results to come back very fast, it makes it quite annoying to deal with
--
Edit bug report at http://bugs.php.net/?id=36384&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36384&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36384&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36384&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36384&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36384&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36384&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36384&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36384&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36384&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36384&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36384&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36384&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36384&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36384&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36384&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36384&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36384&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36384&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36384&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36384&r=mysqlcfg