|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27552 fwrite fails after writing 8k bytes
Submitted: 2004-03-10 11:39 UTC Modified: 2004-08-17 20:26 UTC
Avg. Score:5.0 ± 0.0
Reproduced:5 of 6 (83.3%)
Same Version:0 (0.0%)
Same OS:1 (20.0%)
From: jeroen dot pulles at redslider dot net Assigned: wez (profile)
Status: Closed Package: Sockets related
PHP Version: 5CVS-2004-03-10 (dev) OS: win32
Private report: No CVE-ID: None
 [2004-03-10 11:39 UTC] jeroen dot pulles at redslider dot net
When writing data to a socket, the program fails when writing more than 8192 bytes, irrespective of a given buffersize. 

- Windows 2000
- RC1-dev (-200403101130)
- Command line interface (using cygwin)
- Almost no modules, just php_sockets.dll
- Default php.ini(-dist), apart from 
  E_ALL for the error logging

The socket shouldn't be blocking, I didn't ask for it, and set_stream_blocking(true) doesn't change it; I'm guessing this is some irrelevant (for me) implementation detail for PHP.

Writing to localhost does work.

Writing less than 8192 bytes does work (well, didn't check the exact size where failure starts to happen).

No problems on my Linux box and PHP 5.*.

Reproduce code:
    $socket = fsockopen('some-other-host', 80, $errno, $errmessage);
    $message_body = '';
    for ($i = 0; $i < 4000; $i++) $message_body .= 'yadda ';
    $contentlength = strlen($message_body);
    $message = "POST / HTTP/1.0\r\n";
    $message .= "Host: some-other-host\r\n";
    $message .= "Content-Type: text/plain\r\n";
    $message .= "Content-Length: $contentlength\r\n";
    $message .= "\r\n";
    $message .= $message_body;
    fwrite($socket, $message);

Expected result:
Expecting to just see "Done"

Actual result:
JeroenP@geneva$ bin/php fwrite-bug.php

Notice: fwrite(): send of 8192 bytes failed with errno=0 A non-blocking socket o
peration could not be completed immediately.
 in C:\home\wwwroot\aria\fwrite-bug.php on line 12


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-10 12:06 UTC]
Please try using this CVS snapshot:
For Windows:

Please try a real windows binary, not a cygwin emulation and see if the problem persists.
 [2004-03-11 02:53 UTC] jeroen dot pulles at redslider dot net
I am using the latest windows binary snapshot. 

(It's just that I'm not using the regular cmd.exe for command line work, but cygwin's bash.exe shell; Which is probably irrelevant anyway. For the record: I get the same result when running the reproduce code from cmd.exe.)
 [2004-04-07 06:03 UTC]
I can't reproduce this either. Are you sure there isn't some firewall or something in between that might somehow break this..?

 [2004-04-13 17:47 UTC] jeroen dot pulles at redslider dot net
I am still experiencing the problem with RC2-dev (April 12th windows snapshot).

I tried the code on two networks. One network has a transparent firewall as far as HTTP traffic is concerned. The other is my home network, behind a simple router/nat solution. I have no reason to believe anything is tampering the data; Especially since a smaller message body _does_ work. 

I put up a simple test case on my website:

I have no problem running fwrite_test.php with a small message size. However, the code still breaks when writing more than 8192 bytes. 

What I find weird is that the code runs fine, in any case, on a localhost webserver/website, but breaks on any remote host, irrespective of webserver software etcetera etcetera. I'm puzzled. 

Help is appreciated, 
 [2004-07-21 12:57 UTC] ulf at haueisen dot net
I experience the same with PHP 5.0.0 final on Windows Server 2003 using PEAR HTTP_Request while sending more than 8k POST-Data.
 [2004-07-21 13:48 UTC] ulf at haueisen dot net
btw: It does work correctly with PHP 4.3.8.
 [2004-08-17 00:29 UTC] ulf at haueisen dot net
I think this is a duplicate of 29256 and fixed in PHP 5.0.1


 [2004-08-17 08:08 UTC]
Please try using this CVS snapshot:
For Windows:

 [2004-08-17 20:26 UTC] jeroen dot pulles at redslider dot net
The problem seems to have disappeared; Just tested 
the reproduce code using 5.1.0-dev ('latest'), 
and it ran fine. 

-- jeroen
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 08:01:28 2024 UTC