Skip to content

Instantly share code, notes, and snippets.

@choult
Created June 19, 2019 15:53
Show Gist options
  • Save choult/5d45e360527842f59c588f99d77eb517 to your computer and use it in GitHub Desktop.
Save choult/5d45e360527842f59c588f99d77eb517 to your computer and use it in GitHub Desktop.
<?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