Question

MySQL server has gone away

Hello! While running a PHP script I’ve encountered an error that says the MySQL server has gone away and it’s really getting annoying.

I’ve tried the following things with no success. Add these to /etc/mysql/my.cnf

wait_timeout = 28800
interactive_timeout = 28800
max_allowed_packet	= 256M

I’ve tried adding this to php.ini as well.

mysql.connect_timeout = 240

Nothing seems to work.

Thank you!

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi, what about if the error is in this line?

$link->ssl_set(‘client-key.pem’, ‘client-cert.pem’, ‘ca.pem’, NULL, NULL);

where put this mysql.connect_timeout = 300 default_socket_timeout = 300 lines ?

@matthew6d Create a file that contains the following and call it phpinfo.php and place it in your web root and open your browser to that page.

<?php phpinfo();

Then you will see all parameters used by PHP and you can search for each configuration to see what setting it’s using.

Hi @matthew6d

You shouldn’t need to change anything in MySQL - it’s by default set to some ridiculous high timeout. But PHP has normally a timeout on 30 or 60 seconds for most things. Can you set the following two PHP configurations (300 seconds = 5 minutes):

mysql.connect_timeout = 300
default_socket_timeout = 300