I have this loop:
//open archive $zip
$start = hrtime(true);
while(true) {
$zip->addFile($files[$i++]);
$end = hrtime(true);
$time = ($end - $start) / 1e+9; // convert to seconds
if( $time > 10.0) {
break;
}
}
echo $i;
I found that the timer does not accurately stops after 10sec. Whereas if I replace the loop with the following:
//open archive $zip
$start = hrtime(true);
while(true) {
sleep(1); // simulate work
$end = hrtime(true);
$time = ($end - $start) / 1e+9; // convert to seconds
if( $time > 10.0) {
break;
}
}
echo $i;
The loop does stop after 10 or more seconds. Is ZipArchive::addFile() doing something to the hardware timer the prevents predicting proper time difference?
I understand I could use microtime(true) but I understand it might be even less accurate in VM environments.