Home  >  Article  >  Backend Development  >  Is the mysql.connect_timeout PHP Option Causing MySQL Server Connection Timeouts After 60 Seconds?

Is the mysql.connect_timeout PHP Option Causing MySQL Server Connection Timeouts After 60 Seconds?

Barbara Streisand
Barbara StreisandOriginal
2024-10-18 22:10:30338browse

Is the mysql.connect_timeout PHP Option Causing MySQL Server Connection Timeouts After 60 Seconds?

MySQL Server disconnection problem: disconnected 60 seconds after timeout

Problem:

I discovered that a SQL query that previously ran fine now times out after 60 seconds and throws an error. Even though the query is slow, it's run as part of a nightly job, so it's not a problem per se (so please don't suggest I optimize it).

I can consistently reproduce the error by running "select SLEEP(120);" from PHP as shown below. However, running the same statement from the MySQL client is successful (returns 0). I tried adjusting wait_timeout (set to 28800) with no success. I also restarted the database server and the computer itself.

I always get a timeout of exactly 60 seconds, which makes me think it might be a setup issue rather than a resource constraint issue.

I'm running:

  • Windows Server 2003
  • MySQL 5.1.36-community
  • PHP 5.3

The following is my test code, output and results of SHOW VARIABLES.

... 代码、输出和 SHOW VARIABLES 如下所示 ...

Answer:

php option mysql.connect_timeout is the cause of this issue. It is used not only for connection timeouts but also for waiting for the first response from the server. You can increase it like this:

ini_set('mysql.connect_timeout', 300);
ini_set('default_socket_timeout', 300); 

The above is the detailed content of Is the mysql.connect_timeout PHP Option Causing MySQL Server Connection Timeouts After 60 Seconds?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn