pcntl_signal_dispatch

(PHP 5 >= 5.3.0)

pcntl_signal_dispatchAskıdaki sinyaller için sinyal eylemciyi çağırır

Açıklama

bool pcntl_signal_dispatch ( void )

Askıdaki her sinyal için pcntl_signal() tarafından tanımlanmış eylemci işlevi çağırır.

Dönen Değerler

Başarı durumunda TRUE, başarısızlık durumunda FALSE döner.

Örnekler

Örnek 1 - pcntl_signal_dispatch() örneği

<?php
echo "Sinyal eylemcimizi kuralım...\n";
pcntl_signal(SIGHUP,  function($signo) {
     echo 
"sinyal eylemci çağrıldı\n";
});

echo 
"Kendimize SIGHUP gönderelim...\n";
posix_kill(posix_getpid(), SIGHUP);

echo 
"Sinyal yakalanıyor...\n";
pcntl_signal_dispatch();

echo 
"Bitti\n";

?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

Sinyal eylemcimizi kuralım...
Kendimize SIGHUP gönderelim...
Sinyal yakalanıyor...
sinyal eylemci çağrıldı
Bitti

Ayrıca Bakınız

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