Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron Job PHP script execution time report

Tags:

php

cron

My question is simple: I want to know how long a PHP script is taking to execute. On top of this, I am executing it via cron. Now, I could do something via the PHP code itself to get the execution time start/end, however I wondered if there was something via the cron command that I could add to get that emailed to me, in milliseconds?

Currently I am using:

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

Which runs my script and stops all errors/output getting emailed to me. Can I change the above to get the execution time emailed to me somehow?

Thanks

like image 272
mootymoots Avatar asked Dec 20 '10 22:12

mootymoots


3 Answers

/usr/bin/time /usr/bin/php -q httpsdocs/folder/script.php
 | mail -s "Some Subject" [email protected]

:-)

like image 140
Ehsan Avatar answered Oct 27 '22 13:10

Ehsan


You can use time command like this:

/usr/bin/time /usr/bin/php -q httpsdocs/folder/script.php > /var/log/crontiming
like image 30
ncuesta Avatar answered Oct 27 '22 11:10

ncuesta


By the given script you can change the cron job execution time.

$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); 
like image 30
Harsh Punnoose Avatar answered Oct 27 '22 13:10

Harsh Punnoose