Hi, I have the following PHP code for writing to a filepointer $fp
that was opened using fsockopen
:
syslog(LOG_INFO, "Write " . strlen($buf) . " bytes to socket:");
$bytes = 0;
while ($bytes < strlen($buf) && ($w = @fwrite($fp, substr($buf, $bytes))))
{
syslog(LOG_INFO, " - " . $w . " bytes written to socket");
$bytes += $w;
}
if ($bytes != strlen($buf))
{
syslog(LOG_INFO, "error while writing to socket");
exit();
}
This code works fine as long as the size of $buf
is small enough. A large amount of data cannot be written completely. I get the following output:
Write 4900360 bytes to socket:
- 11096 bytes written to socket
error while writing to socket
btw. the return value of fwrite
is 0
and not false
.
Does anybody has an idea what could be the problem? Thanks a lot for your answers
I get the following notices when removing the @ in front of the fwrite:
Notice: fwrite(): send of 8192 bytes failed with errno=104 Connection reset by peer in /root/test.php on line 10
Notice: fwrite(): send of 8192 bytes failed with errno=32 Broken pipe in /root/test.php on line 10
I just sniffed the TCP Stream and I figured out, that I get a
HTTP/1.1 413 Request Entity Too Large
Is there any fix to this problem? I use a lighttpd/1.4.22 server