1 Problem Description: Client link to MySQL server is broken
2 Causes of problems:
1> MySQL service is down 2> mysql link timeout 3>mysql request link process is active kill : Query result set exceeds Max_allowed_packet
3 Workaround:
Way One:
Of course is to increase your wait-timeout value, this parameter is set in MY.CNF (under Windows step down is My.ini),
My database load is a little bit larger, so I set the value to 10, (the unit of this value is seconds,
This means that when a database connection does not have any action within 10 seconds, it will be forcibly closed.
I'm not using a permanent link (mysql_pconnect), with Mysql_connect,
You can see the results of this wait-timeout in the MySQL process list (show processlist),
You can set this wait-timeout to larger, such as 300 seconds, hehe, generally speaking 300 seconds enough to use,
In fact you can also not set, MySQL default is 8 hours. The situation is determined by your server and site.
Way two:
This is also my personal view of the best method, that is, check the status of MySQL link, so that it relink.
Maybe we all know that there is mysql_ping such a function, in a lot of information that this mysql_ping API will check whether the database is linked,
If it is disconnected, it will try to reconnect, but in my test I found that it is not the case, it is conditional,
Must pass the relevant parameter through Mysql_options this C API, let MySQL have the option of Disconnecting automatic link (mysql default is not automatically connected),
But I test found PHP in the MySQL API does not carry this function, you re-edit MySQL bar, hehe.
But mysql_ping this function is finally able to use, but in which there is a small operation skills:
This is one of the functions in the middle of my database operations class
MySQL server has gone away