Last active
December 16, 2015 22:15
-
-
Save bobmagicii/395e856a3c5b5dd6e443 to your computer and use it in GitHub Desktop.
enter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
C:\Users\bob\Desktop>php plzwait.php | |
1450303435.52 | |
1450303436.0004 | |
*/ | |
function WaitForPerigee() { | |
// wait until the last possible moment so that we have as much of the | |
// full second possible to work within. | |
$Time = microtime(true); | |
time_nanosleep(0,((((int)($Time+1)-$Time)+0.001)*1000000000)); | |
return; | |
} | |
function ReallyWaitForPerigee() { | |
// reimplementation to avoid rounding errors from WaitForPerigee. | |
$Time = time(); | |
while(time() === $Time) { } | |
return; | |
} | |
function DoShit() { | |
// this is where you do your work. this demo will just print the time | |
// to show that we had our maximum available timeslice. | |
echo microtime(true), PHP_EOL; | |
return; | |
} | |
echo microtime(true), PHP_EOL; | |
ReallyWaitForPerigee(); | |
DoShit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment