php提前终止,由于最大执行时间致命错误,PHP cron作业提前终止

我有一个

PHP cron作业,运行29分钟后失败.日志中的错误(/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

触发cron的crontab条目是:

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

从我的研究中我不认为这与max_execution_time配置设置有关,因为:

>我知道它的运行时间为29:18分钟(即错误信息大约超过60秒).

>从the PHP docs开始 – 从命令行运行PHP时,默认设置为0.

问:为什么脚本会提前终止?

笔记:

该脚本非常繁重,并且运行了数千个数据库查询,但我运行的是顶级且CPU负载不高.

错误日志中的行是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)

更新 – 我发现为什么脚本可以运行29分钟的实时,但PHP可以退出引用执行时间低得多.

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.

(从the set_time_limit() docs开始,也在the max-execution-time docs中提到).这对我来说很重要,因为大多数脚本都是长时间运行的数据库查询和支付API调用,这些调用不会占用执行时间.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值