php.net |  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
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-13 19:08 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [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-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC