我有以下 PHP 代码用于写入使用以下命令$fp
打开的文件指针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();
}
只要 的大小$buf
足够小,此代码就可以正常工作。大量数据无法完全写入。我得到以下输出:
Write 4900360 bytes to socket:
- 11096 bytes written to socket
error while writing to socket
顺便提一句。fwrite
is0
和 not的返回值false
。
有人知道可能是什么问题吗?非常感谢你的回答
删除 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
我只是嗅探了 TCP 流,我发现,我得到了一个
HTTP/1.1 413 Request Entity Too Large
这个问题有什么解决办法吗?我使用 lighttpd/1.4.22 服务器