-
-
Save halaei/b6a480e67d7c9306c7e48405902b0aa9 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 | |
declare(ticks = 1); | |
class TimeoutException extends Exception {}; | |
function signal_handler($signal) { | |
throw new TimeoutException(); | |
} | |
pcntl_signal(SIGALRM, "signal_handler", true); | |
pcntl_alarm(1); | |
try { | |
// simulate long executing block | |
while(1) sleep(30); | |
} catch(TimeoutException $e) { | |
echo "Timeout exceeded"; | |
} | |
echo "done"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment