首頁 > php框架 > Workerman > 主體

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

藏色散人
發布: 2021-02-01 12:06:20
原創
3252 人瀏覽過

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長時間連結資料庫,資料庫斷開會重連。

以上是workerman+tp5的錯誤問題怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!