note 26251 modified in function.register-shutdown-function by danbrown
| From: | danbrown@php.net | Date: | Sat, 19 Jul 2008 23:27:07 +0000 |
| Subject: | note 26251 modified in function.register-shutdown-function by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141791@lists.php.net to get a copy of this message | ||
When using CLI ( and perhaps command line without CLI - I didn't test it) the shutdown function
doesn't get called if the process gets a SIGINT or SIGTERM. only the natural exit of PHP calls
the shutdown function.
To overcome the problem compile the command line interpreter with --enable-pcntl and add this code:
<?php
function sigint()
{
exit;
}
pcntl_signal(SIGINT, 'sigint');
pcntl_signal(SIGTERM, 'sigint');
?>
This way when the process recieves one of those signals, it quits normaly, and the shutdown function
gets called.
Note: using the pcntl function in web server envoirment is considered problematic, so if you are
writing a script that runs both from the command line and from the server, you should put some
conditional code around that block that identifies wheater this is a command line envoirment or not.
--was--
When using CLI ( and perhaps command line without CLI - I didn't test it) the shutdown function
doesn't get called if the process gets a SIGINT or SIGTERM. only the natural exit of PHP calls
the shutdown function.
To overcome the problem compile the command line interpreter with --enable-pcntl and add this code:
function sigint()
{
exit;
}
pcntl_signal(SIGINT, 'sigint');
pcntl_signal(SIGTERM, 'sigint');
This way when the process recieves one of those signals, it quits normaly, and the shutdown function
gets called.
Note: using the pcntl function in web server envoirment is considered problematic, so if you are
writing a script that runs both from the command line and from the server, you should put some
conditional code around that block that identifies wheater this is a command line envoirment or not.
http://php.net/manual/en/function.register-shutdown-function.php