How to keep a php script from timing out because of a long mysql query

后端 未结 5 1771
盖世英雄少女心
盖世英雄少女心 2020-12-29 11:07

I have an update query being run by a cron task that\'s timing out. The query takes, on average, five minutes to execute when executed in navicat.

The code looks ro

相关标签:
5条回答
  • 2020-12-29 11:16

    According to the manual:

    Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running.

    So it's unlikely to have anything to do with PHP's time limit. What message are you getting when it times out? Perhaps there's a MySQL setting involved.

    0 讨论(0)
  • 2020-12-29 11:19

    Is your php running in safe-mode? Quote from PHP manual of set_time_limit:

    This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.

    0 讨论(0)
  • 2020-12-29 11:19

    Assuming you are on linux, Debian based systems have separate configurations for mod_php/php cgi and php-cli. This shouldn't be too difficult to set up on a different linux system that doesn't separate cgi/cli configuration.

    Once you have separate configs, I would adjust your php cli configuration. Disable safe mode and any time limits and ram limits.

    0 讨论(0)
  • 2020-12-29 11:41

    I had the same problem somwhere, and "solved" it with the following code (first two lines of my file):

    set_time_limit(0);
    ignore_user_abort(1);
    
    0 讨论(0)
  • 2020-12-29 11:41

    Check out some of the resource limit variables in php,ini: max_execution_time, max_input_time, memory_limit

    You could also set a time limit for the script in PHP itself: http://ca3.php.net/set_time_limit

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