workerman+tp5的錯誤問題怎么解決

workerman+tp5的錯誤問題怎么解決

workerman+tp5的錯誤問題怎么解決?thinkphp5+workerman 報錯問題

在thinkphp5.0.X版本早期會遇到長時間開啟workerman服務會報錯,在thinkphp5.0.24版本已經修復。原因是因為長時間鏈接數據庫,導致數據庫斷線。

推薦:《Workerman教程

解決的方案:

1、修改數據庫配置database.php文件,將break_reconnect參數設置為true。斷線重連。

//?是否需要斷線重連 'break_reconnect'?=>?true,

2、修改 /library/think/db/Connection.php中的isBreak函數,替換為以下最新的isBreak函數。

??/** ?????*?是否斷線 ?????*?@access?protected ?????*?@param?PDOException|Exception??$e?異常對象 ?????*?@return?bool ?????*/ ????protected?function?isBreak($e) ????{ ????????if?(!$this->config['break_reconnect'])?{ ????????????return?false; ????????} ? ????????$info?=?[ ????????????'server?has?gone?away', ????????????'no?connection?to?the?server', ????????????'Lost?connection', ????????????'is?dead?or?not?enabled', ????????????'Error?while?sending', ????????????'decryption?failed?or?bad?record?mac', ????????????'server?closed?the?connection?unexpectedly', ????????????'SSL?connection?has?been?closed?unexpectedly', ????????????'Error?writing?data?to?the?connection', ????????????'Resource?deadlock?avoided', ????????????'failed?with?errno', ????????]; ? ????????$error?=?$e->getMessage(); ? ????????foreach?($info?as?$msg)?{ ????????????if?(false?!==?stripos($error,?$msg))?{ ????????????????return?true; ????????????} ????????} ????????return?false; ????}

3、將/library/think/db/connector/mysql.php中的isBreak函數刪除或者注釋掉。

修改完后,Workerman教程長時間鏈接數據庫,數據庫斷開會重連。

以上就是

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