Cron Job PHP脚本执行时间报告

时间:2010-12-20 22:41:02

标签: php cron

我的问题很简单:我想知道PHP脚本执行的时间。最重要的是,我通过cron执行它。现在,我可以通过PHP代码本身做一些事情来获得执行时间的开始/结束,但是我想知道是否有一些东西通过cron命令我可以添加以通过电子邮件发送给我,在几毫秒内?

目前我正在使用:

/usr/bin/php -q httpsdocs/folder/script.php > /dev/null 2>&1

哪个运行我的脚本并停止通过电子邮件发送给我的所有错误/输出。我可以更改以上内容以某种方式通过电子邮件将执行时间发送给我吗?

由于

3 个答案:

答案 0 :(得分:5)

/usr/bin/time /usr/bin/php -q httpsdocs/folder/script.php
 | mail -s "Some Subject" you@youremailid.com

: - )

答案 1 :(得分:4)

您可以使用time命令:

/usr/bin/time /usr/bin/php -q httpsdocs/folder/script.php > /var/log/crontiming

答案 2 :(得分:1)

通过给定的脚本,您可以更改cron作业执行时间。

$aCronList = array();
$result = -1;
exec('crontab -l', $aCronList, $result);
foreach($aCronList AS $item)
{
    // Find what you want, replace the times
}

$sCronList = implode(PHP_EOL, $aCronList);
exec('crontab < ' . $sCronList); 
相关问题