Created
June 19, 2019 15:53
-
-
Save choult/5d45e360527842f59c588f99d77eb517 to your computer and use it in GitHub Desktop.
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 | |
class Timeout extends \RuntimeException { | |
} | |
function setRequestTimeout($timeout) { | |
$start = microtime(true); | |
register_tick_function(function () use ($start, $timeout) { | |
print microtime(true) - $start . " "; | |
print "tick\n"; | |
if (microtime(true) - $start > $timeout) { | |
throw new Timeout(); | |
} | |
}); | |
} | |
declare(ticks=100); | |
setRequestTimeout(5); | |
$i = 0; | |
while (true) { | |
print $i++; | |
print "\n"; | |
usleep(100000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment