[PHP4] gettimeofday()
| From: | Remco Chang | Date: | Mon, 07 Aug 2000 17:12:19 +0000 |
| Subject: | [PHP4] gettimeofday() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-10504@lists.php.net to get a copy of this message | ||
hi,
i've been testing out the performance of php4 with apache and odbc driver
(oob by easysoft.com) using gettimeofday() to find the amount of elapsed
time... i'm running php4.0.1pl2 on redhat 6.2 with apache 1.3.12.
the problem that i'm having is that gettimeofday seems to return time that
"jumps backwards in time." here's an example of what i would get when i
write a for loop to grab the current time ten thousand times:
time: 965666189.9983
time: 965666189.99903
time: 965666189.99976
time: 965666181.00049 **********
time: 965666181.00123
time: 965666181.00197
note that this does not happen all the time... i would say in 10,000
times, this happens about 5 times or so. also note that strange enough,
it always seems to jump backwards 9 seconds percisely... *boggle*
i wrote a small program in c to test the <sys/time.h> gettimeofday()
function to make sure that it's not a hardware issue, and it's not. :)
does any one know if this is a problem with apache, php, or a combination
of the two? is this a bug or is it due to some "smart forking" that php
does to optimize for loops?
thanx in advance for any help!
attached is the program i wrote for testing:
<?php
function getCurrentTime () {
$time_array = gettimeofday();
return $time_array["sec"] + ($time_array["usec"]/100000);
}
$cache_time = 0;
$cur_time = 0;
echo "test starts...";
for ($i=0; $i<10000; $i++) {
$cur_time = getCurrentTime();
echo "<br>time: $cur_time";
if ($cur_time < $cache_time) { //if time starts going backwards
echo " **********";
}
$cache_time = $cur_time;
}
?>
----------------
remco chang
bountyquest.com