Calculate Script Duration in PHP and BASH
BASH
#!/bin/bash #start of script time_start=`date +%s` #do stuff sleep 65 #end of script time_end=`date +%s` time_elapsed=$((time_end - time_start)) echo "script executed in $time_elapsed seconds" echo $(( time_elapsed / 60 ))m $(( time_elapsed % 60 ))s
Replace "sleep 65" above with the bash command you wish to time.
PHP
<?php //put this at the start of your php script. $s_mt = explode(" ",microtime()); //do stuff sleep(65); //put this at the end of your php script $e_mt = explode(" ",microtime()); $s = (($e_mt[1] + $e_mt[0]) - ($s_mt[1] + $s_mt[0])); echo "script executed in ".$s." seconds"; echo ($s/60)."m ".($s%60)." s"; ?>
In both cases it would output:
script executed in 65 seconds 1m 5s
code snippets are licensed under Creative Commons CC-By-SA 3.0 (unless otherwise specified)