PHP cron job abort due to runtime error

I have a cron PHP job that does not work after starting for 29 minutes. Error in log ( /var/log/php_errors.log):

[01-Mar-2012 00:32:57 UTC] PHP Fatal error: Maximum execution time of 60 seconds exceeded in /path/file.php on line 2079

The crontab entry that starts cron:

00 00 * * * /usr/bin/php /path/file.php

From my research, I do not think that this is related to configuration max_execution_time, because:

  • I know that it works for 29:18 minutes (i.e. much more than the 60s as an error message).
  • From PHP Docs - When starting PHP from the command line, the default value is 0.

Q: Why does the script end?


Notes:

The script is very heavy and executes many thousands of database queries, but I did top, and the CPU load was low.

The line from the error log is the call mysql_query:

$sql = "SELECT SUM(amount) FROM mytab WHERE mem = '$id' AND validto > '$now'";
$res = mysql_query($sql);

> php -v
PHP 5.3.10 (cli) (built: Feb  2 2012 17:34:38) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH

> cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.7 (Tikanga)

. , script 29 , PHP .

, , script, system(), , .., , script .

( ___(), max-execute-time docs). , script db API , .

+5
3

PHP Fatal error: Maximum execution time of 60 seconds exceeded, some PHP- set_time_limit(60) -. CLI PHP timelimit, , . , PHP , , set_time_limit , / , 60 .

set_time_limit. , set_time_limit(0) script, , 60 . , Ubuntu LTS CLI PHP /etc/php5/cli/php.ini.

+1

, , , set-time-limit():

<?php set_time_limit(0); ?>

script

ignore_user_abort(1);
+2

, , , , ? -?

, , script, "/usr/bin/php/path/file.php" .

00 00 * * */usr/local/scripts/start_php_job.sh

File: /usr/local/scripts/start_php_job.sh
#!/usr/bin/bash
date

/usr/local/bin/php /path/to/script

date
+1
source

All Articles