PHP MySQL set Connection Timeout

后端 未结 6 685
醉梦人生
醉梦人生 2020-12-17 18:19

There are certain posts on MySQL connection set time out from PHP using mysql.connect_timeout. I want to know if this set timeout from PHP just time out the initial connecti

相关标签:
6条回答
  • 2020-12-17 18:49

    The connect_timeout parameter is only valid at connection time. It's useful to check if your DB server is reachable in 20 seconds or so. Once connected the specified timeout is no longer valid.

    I don't find any query timeout parameter on official mysql manual page: http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html so I don't think this is possibile.

    0 讨论(0)
  • 2020-12-17 18:54

    Use MySQL version 5.7.4 or above and set appropriate "max_statement_time" variable, query will fail if timeout is reached

    see http://mysqlserverteam.com/server-side-select-statement-timeouts/

    0 讨论(0)
  • 2020-12-17 18:54

    It is in your php configuration file. The location of this file is different from one system to the other. On Ubuntu and Debian it is located in /etc/php5/apache2/php.ini

    mysql.connect_timeout = 60 /* the default value is 60 seconds */
    
    0 讨论(0)
  • 2020-12-17 18:58

    You would have to fork a child process, the parent process will kill the child process if some condition is not met within 20 seconds.

    Or use a language like node.js that doesn't block the current thread for an IO operation like a query.

    0 讨论(0)
  • 2020-12-17 19:00

    see it:

    set_time_limit(0);   
    ini_set('mysql.connect_timeout','0');   
    ini_set('max_execution_time', '0');   
    
    0 讨论(0)
  • 2020-12-17 19:11

    sigalarm is your friend. You can set a alarm, and use a signal handler to detect the alarm.

    http://php.net/manual/en/function.pcntl-alarm.php

    0 讨论(0)
提交回复
热议问题