|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36384 fwrite buffers when writing to socket
Submitted: 2006-02-13 17:46 UTC Modified: 2006-02-13 21:42 UTC
From: djgrrr at gmail dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 4.4.2 OS: Linux 2.6
Private report: No CVE-ID: None
 [2006-02-13 17:46 UTC] djgrrr at gmail dot com
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:
$s = fsockopen("localhost",23);
$i = 0;
while ($i < 1000) {
if (feof($s))
if ($in != "")
   // 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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-13 19:08 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-02-13 21:41 UTC] djgrrr at gmail dot com
sorry guys, this was my stupidity, not a bug at all :P
 [2006-02-13 21:42 UTC] djgrrr at gmail dot com
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 25 22:01:29 2024 UTC