June 2017
Intermediate to advanced
536 pages
9h 49m
English
The pcntl_alarm() function enriches the PHP signals functionality by providing an alarm clock for delivery of a signal. Simply put, it creates a timer that sends a SIGALRM signal to the process after a given number of seconds.
Once the alarm is fired, the signal handler function kicks in. Once the signal handler function code is done executing, we are taken back to the point in code where the application stopped before jumping into a signal handler function.
Let's take a look at the following piece of code:
#!/usr/bin/env php<?phpdeclare(ticks = 1);echo 'started' . PHP_EOL;function signalHandler($signal){ echo 'Triggered signalHandler: ' . $signal . PHP_EOL;}pcntl_signal(SIGALRM, 'signalHandler');pcntl_alarm(7);while (true) { echo ...