pcntl_signal

pcntl_signal -- Installs a signal handler

Description

bool pcntl_signal ( int signo, mixed handle)

pcntl_signal( ) returns TRUE on success or FALSE on failure .

דוגמה 1 . pcntl_signal( ) Example

 
?php

 
/

 
/

 
signal

 
handler

 
function

 
function

 
sig_handler(

 
$signo

 
)

 
{

 
switch($signo

 
)

 
{

 
case

 
SIGTERM

 
:

 
/

 
/

 
handle

 
shutdown

 
tasks

 
exit

 
;

 
break

 
;

 
case

 
SIGHUP

 
:

 
/

 
/

 
handle

 
restart

 
tasks

 
break

 
;

 
case

 
SIGUSR1

 
:

 
print

 
"Caught

 
SIGUSR1...\n"

 
;

 
break

 
;

 
default

 
:

 
/

 
/

 
handle

 
all

 
other

 
signals

 
     }

 

}

 
print

 
"Installing

 
signal

 
handler...\n"

 
;

 
/

 
/

 
setup

 
signal

 
handlers

 
pcntl_signal(SIGTERM

 
,

 
"sig_handler")

 
;

 
pcntl_signal(SIGHUP

 
,

 
"sig_handler")

 
;

 
pcntl_signal(SIGUSR1

 
,

 
"sig_handler")

 
;

 
print

 
"Generating

 
signal

 
SIGTERM

 
to

 
self...\n"

 
;

 
/

 
/

 
send

 
SIGUSR1

 
to

 
current

 
process

 
id

 
posix_kill(posix_getpid()

 
,

 
SIGUSR1)

 
;

 
print

 
"Done\n

 
"

 

?