MySQL server has gone away, PDO and max_allowed_packet in PHP

895 views Asked by At

Do you know how to avoid the following fatal error message :

"...MySQL server has gone away".

I suppose this means that PDO connection to MySQL has been lost.

I have checked MySQL max_allowed_packet variable which is equal to 268435456 (I think this value is more than enough).

3

There are 3 answers

0
Jam On BEST ANSWER

Thanks for your respective answers. After few days of investigations, I decided to reset PDO MySQL connection every 250 seconds. I know it is not the best in class solution but it is at least a solution to avoid the problem.

0
Baasic On

There is no way to "avoid" this error. This error happens when you lose connection to the DB server. This can happen for a variety of reasons. The most common reason for the MySQL server has gone away error, is that the server timed out and closed the connection.

Some other common reasons are:

  • You (or the db administrator) has killed the running thread.
  • You tried to run a query after closing the connection to the server.
  • You got a timeout from the TCP/IP connection on the client side.
  • You have encountered a timeout on the server side and the automatic reconnection in the client is disabled.
  • And more.

Check out this link from the MYSQL docs for more info.

0
Curious Mind On

You can check the max_connections and make sure they aren´t reached - that´s the most common cause I remember for you to get this error.