我有写一个文件指针$fp
这是使用fsockopen
打开下面的PHP代码:PHP的fwrite的停止写入套接字文件指针
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
btw。 fwrite
的返回值是0
而不是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服务器
删除fwrite之前的@,它几乎肯定会打印出具有相关细节的警告。 – nothrow 2010-07-22 13:12:33
fwrite不会产生任何警告。返回值是0而不是false,这意味着该命令没有失败,但没有写入任何字节(根据文档) – 2010-07-22 13:24:19
我现在把error_reporting(E_ALL)放在我的代码前面,我得到以下通知: ():发送8192字节失败,errno = 104在第10行的/root/test.php中由对等端重置连接 注意:fwrite():发送8192字节失败,errno = 32中断管道在/root/test.php在线10 我很高兴为任何翻译:) ...但为什么fwrite的返回值不是false? – 2010-07-22 15:42:46