pcntl_signal_dispatch

(PHP 5 >= 5.3.0)

pcntl_signal_dispatchCalls signal handlers for pending signals

Descrierea

bool pcntl_signal_dispatch ( void )

The pcntl_signal_dispatch() function calls the signal handlers installed by pcntl_signal() for each pending signal.

Valorile întoarse

Întoarce valoarea TRUE în cazul succesului sau FALSE în cazul eșecului.

Exemple

Example #1 pcntl_signal_dispatch() example

<?php
echo "Installing signal handler...\n";
pcntl_signal(SIGHUP,  function($signo) {
     echo 
"signal handler called\n";
});

echo 
"Generating signal SIGHUP to self...\n";
posix_kill(posix_getpid(), SIGHUP);

echo 
"Dispatching...\n";
pcntl_signal_dispatch();

echo 
"Done\n";

?>

Exemplul de mai sus va afișa ceva similar cu:

Installing signal handler...
Generating signal SIGHUP to self...
Dispatching...
signal handler called
Done

Vedeți de asemenea

add a note add a note

User Contributed Notes 2 notes

up
2
webmaster at ajeux dot com
4 years ago
If you are running PHP as CLI and as a "daemon" (i.e. in a loop), this function must be called in each loop  to check if new signals are waiting dispatching.
up
0
me at subsonic dot cz
2 months ago
Note that calling pcntl_signal_dispatch() from within a signal handler invoked by a previous pcntl_signal_dispatch() will not trigger handlers for any new pending signals. This means that if you write a CLI daemon which forks off child processes in response to a signal, then those child processes won't be able to respond to signals. This gave me a headache for a while as pcntl_signal_dispatch() doesn't raise any errors when this occurs. One solution is to set a flag within the signal handler and react upon it (by forking off the needed child processes) elsewhere in the parent process's main loop.
To Top