?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
"
?
|