Home>Article>PHP Framework> How to solve the error problem of workerman+tp5

How to solve the error problem of workerman+tp5

藏色散人
藏色散人 Original
2020-02-04 14:03:01 3160browse

How to solve the error problem of workerman+tp5

How to solve the error problem of workerman tp5? thinkphp5 workererman error reporting problem

In the early version of thinkphp5.0. The reason is that the database is disconnected due to long-term connection to the database.

Recommended: "Workerman Tutorial"

Solution:

1. Modify the database Configure the database.php file and set the break_reconnect parameter to true. Disconnect and reconnect.

// 是否需要断线重连 'break_reconnect' => true,

2. Modify the isBreak function in /library/think/db/Connection.php and replace it with the latest isBreak function below.

/** * 是否断线 * @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. Delete or comment out the isBreak function in /library/think/db/connector/Mysql.php.

After modification,workermanwill be connected to the database for a long time. If the database is disconnected, it will be reconnected.

The above is the detailed content of How to solve the error problem of workerman+tp5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn