|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46172 fwrite refuses to write more then 32k to non-blocking socket
Submitted: 2008-09-25 11:34 UTC Modified: 2008-09-25 11:45 UTC
From: php at 3r1c dot eu Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.2.6 OS: FreeBSD
Private report: No CVE-ID: None
 [2008-09-25 11:34 UTC] php at 3r1c dot eu
fwrite refuses to write more then 32k to non-blocking socket.
removing the stream_set_blocking line in my sample code will make the program work properly.

It seems to get higher amount written on a localhost socket, about 120kb.

Reproduce code:
#!/usr/local/bin/php -q

// create a string with 100kb of zeros
$bytes = "";
for ($i = 0; $i < 100000; $i++){
$bytes .= "0";

$sock = @stream_socket_client('tcp://', $errno, $errstr, 30);

stream_set_blocking($sock, 0);

$written = fwrite($sock, $bytes);

echo "Wrote $written bytes\n";

Expected result:
Wrote 100000 bytes

Actual result:
Wrote 32768 bytes


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-25 11:45 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

The default tcp socket send buffer on FreeBSD is 32k, you need to change net.inet.tcp.sendspace to a higher value if you want to write more.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 23 13:01:24 2023 UTC