Skip to Content
Mastering PHP 7
book

Mastering PHP 7

by Branko Ajzele
June 2017
Intermediate to advanced
536 pages
9h 49m
English
Packt Publishing
Content preview from Mastering PHP 7

Alarms

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PHP 7

Learning PHP 7

Antonio L Zapata (GBP)
Upgrading to PHP 5

Upgrading to PHP 5

Adam Trachtenberg

Publisher Resources

ISBN: 9781785882814Supplemental Content