我有寫一個文件指針$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