Use pcntl_signal_dispatch() to catch the signal, don't use declare(ticks=1) because it is ineffcient
<?php
pcntl_signal(SIGALRM, function () {
echo 'Received an alarm signal !' . PHP_EOL;
}, false);
pcntl_alarm(5);
while (true) {
pcntl_signal_dispatch();
sleep(1);
}