General error: 2006 MySQL server has gone away [How to Solve]

Congratulations on your journey;

There are many reasons for this. Let’s not talk about the others. Let’s talk about the problems that occurred today; Eliminate the problem of the database itself (my MySQL does not go down at this time.) it is the problem of the program. This problem is that the process always exists, but it has not operated the database for too long, resulting in the disconnection of the database, but suddenly a piece of data comes. At this time, the process will not re link the database, but use the original link (disconnected at this time), so there is no way to find the database, so this error is reported.

Solution:

$round = mt_rand(1, 10);
if ($round == 6) {
    // Query a sql to avoid unavailability of the process due to connection timeout
    $dividend = Db::query("select id from think_member_group where  `id` = 1");
}

A random number. The core of this method is to let your process check the database every few seconds so that the link will not be disconnected.

Read More: