MySQL Server has Gone Away - Exactly in 60 Seconds
In this scenario, a MySQL query that was previously running successfully is now experiencing a timeout after 60 seconds, displaying the error "MySQL server has gone away." The issue persists even though the wait_timeout variable has been adjusted.
Analysis:
The fact that the timeout occurs precisely at 60 seconds suggests that a setting rather than limited resources is the cause. This is supported by the observation that running the same query directly from a MySQL client is successful.
Solution:
The root cause of the problem is the PHP option mysql.connect_timeout. This option determines the time the PHP client waits for the first response from the MySQL server, not just the connection timeout.
To resolve the issue, increase the value of mysql.connect_timeout as follows:
<code class="php">ini_set('mysql.connect_timeout', 300); ini_set('default_socket_timeout', 300); </code>
Explanation:
By increasing the value of mysql.connect_timeout, you extend the time PHP waits for the server's initial response, allowing the query to execute fully within the 60-second window.
The above is the detailed content of Why Does MySQL Server Fade Away Precisely in 60 Seconds?. For more information, please follow other related articles on the PHP Chinese website!