PHP: MySQL server has gone away
you can use mysql_ping()
to see if the connection still connected, if not you can try to reconnnect, or make an error message telling you how far the script had gone before the connection was lost.
Check the value of "max_allowed_packet
" in your my.cnf
MySQL config file.
This happens because the PHP script took too long to process whatever it was processing, and the connection to the server timed out. You have a few solutions:
- Check to make sure the connection is still up, and reconnect if needed (
mysql_connect
has built-in functionality to do that for you) - Use
mysql_pconnect
(but remember to close the connection at the end because it won't close for you) - Improve the running time of your script to avoid the timeout.