Hello,
this is a timer code, but i didn't know how could i convert the output
to be in the format: HH:MM:SS !!
anyone knows?
<?
// this function times the execution of the infinite loop below. After three seconds, it sets end_loop to true (stopping the loop)
function timer () {
// We need a few variables... start_time stores the time of the first execution of this function.
// call_count records the number of times this function is called. Allows you to adjust the number of
// ticks between the call of this function
STATIC $start_time, $call_count;
// We need to set this as global so that, when changed, it will affect the loop.
GLOBAL $end_loop;
// Get the current micro time and split it in to something we can use.
eregi("0.([0-9]+) ([0-9]+)", microtime(), $time);
// Increment the call_count every time this function is called
$call_count++;
// If this is the first time this function is called, then start_time will not have been set yet. We need to do that, then.
if (!isset($start_time)) {
// Record the start time.
$start_time = floatval($time[2] . "." . $time[1]);
// Echo the start time for debugging.
echo "Start Time: ". $start_time ."\n";
} else {
// grab the current time
$current_time = floatval($time[2] . "." . $time[1]);
// If the current time minus the start_time is more than 3, then end this thing!
if (($current_time - $start_time) >= 3) {
// Print out some debug info
echo "End Time: ". $current_time ."\n";
echo "Time Difference: ". ($current_time - $start_time) ."\n";
echo "Number of Function Calls: ". $call_count ."\n";
// set end_loop to true
$end_loop = TRUE;
}
}
}
// Set up a tick handler
register_tick_function("timer");
// This variable will be set to true when the time is up
$end_loop = FALSE;
// Initiate the timer. The first time this function is called, it records the time.
timer ();
// May the threading begin
declare (ticks=200000) {
// An infinite loop. The only way to stop it is to set end_loop to true
while (TRUE) {
if ($end_loop) {
break;
}
}
}
echo "DONE!";
?>
------------------------------------------------
here is the output:
Start Time: 1068359599.9
End Time: 1068359602.98
Time Difference: 3.08199906349
Number of Function Calls: 18
DONE!
timing format!
Moderator: General Moderators