Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start and stop a timer PHP

Tags:

php

timer

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?

like image 753
125369 Avatar asked Nov 29 '11 12:11

125369


People also ask

How to start and stop PHP?

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.

How do I run a function in PHP every 5 seconds?

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.


1 Answers

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

like image 104
Polynomial Avatar answered Sep 22 '22 20:09

Polynomial