|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-02-13 19:08 UTC] tony2001@php.net
[2006-02-13 21:41 UTC] djgrrr at gmail dot com
[2006-02-13 21:42 UTC] djgrrr at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 18:00:01 2025 UTC |
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