I have a php script that gets called frequently that runs a short database query and sends an email. The database code uses procedural-style mysql functions such as
mysql_query(), etc. The email is sent using the
99% of the time it ran without problem. However, sometimes I would get a "MySQL server has gone away" error. The original order of execution was to first send the mail with
mail(), and then run the short update query. I switched the order of execution to run the query first and call
mail() last, and now I never have a problem.
mail() somehow interferes with the database connection occasionally. Anybody have any ideas why? How should go about looking for the problem?
Once the mail script gives the "server went away" error, the query will always fail with that error if I try to run the script again. However, if I run the exact same query in phpMyAdmin it executes with no problem, and afterwards the mail script will work again.
Also, the script ran for many months without any problems - the "server went away" error just started recently, with no changes to any code or configuration on our part. Additionally, the script ran without problems during an extended period of time where the website was getting more than double the amount of traffic it currently gets, so it was not having any problems during a time when the server was dealing with many more database connections, etc., than it is right now.
PHP version: 5.3.3
MySQL version: 5.0.77-log Source distribution
Database is on a different server than the webserver/php script (not connecting to localhost)
Both the webserver and db server are Red Hat Enterprise Linux Server release 5.6 (Tikanga)
You probably have a too short wait-time setting,
official documentation has covered all the scenario
PS AFAIK, there is no
mysql server has went away,
mysql server has gone away