PHP腳本反復出現“send of xxx bytes failed with errno=32 Broken pipe”錯誤怎么辦?

PHP腳本反復出現“send of xxx bytes failed with errno=32 Broken pipe”錯誤怎么辦?

php腳本反復出現“send of xxx bytes failed with errno=32 broken pipe”錯誤

在使用php腳本時,經常會遇到類似“mysqli_query(): send of 309 bytes failed with errno=32 broken pipe”這樣的錯誤。雖然有人建議通過設置max_allowed_packet來解決,但對于沒有超過該設置值的情況,問題可能另有原因。

錯誤原因

broken pipe錯誤通常是由于php腳本mysql服務器之間的連接在長時間無操作后被服務器關閉導致的。當腳本再次嘗試通過該已關閉連接執行查詢時,就會出現該錯誤。

立即學習PHP免費學習筆記(深入)”;

解決方案

要解決此問題,可以嘗試以下方法:

  • 調整mysql服務器的wait_timeout參數:該參數決定了非交互式連接在無活動后多久會被關閉。根據需要將其設置得更大,例如:

    if (!mysqli_ping($conn)) {     // 斷開連接     mysqli_close($conn);      // 重新連接     $conn = mysqli_connect($host, $user, $password, $database); }

    注意,需要使用自己的數據庫連接信息替換 $host、$user、$password 和 $database 變量。

通過調整這些設置,可以在避免遇到 broken pipe 錯誤。

以上就是PHP腳本反復出現“send of xxx bytes f

? 版權聲明
THE END
喜歡就支持一下吧
點贊6 分享