I need some information regarding starting and stopping a timer in PHP. I need to measure the elapsed time from the start of my .exe program (I'm using exec()
function in my php script) until it completes the execution and display the time it took in seconds.
How can I do this?
User Contributed Notes 2 notes If you want your file to be interpreted as php then your file must start and end with <? php and ?> and everything outside of that is ignored by the php parser.
React PHP is a widely used event loop for PHP. define("INTERVAL", 5 ); // 5 seconds function runIt() { // Your function to run every 5 seconds echo "something\n"; } function checkForStopFlag() { // completely optional // Logic to check for a program-exit flag // Could be via socket or file etc. // Return TRUE to stop.
You can use microtime
and calculate the difference:
$time_pre = microtime(true); exec(...); $time_post = microtime(true); $exec_time = $time_post - $time_pre;
Here's the PHP docs for microtime
: http://php.net/manual/en/function.microtime.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With