note 26251 added to function.register-shutdown-function
| From: | php-general at lists dot php dot net | Date: | Thu, 24 Oct 2002 02:35:19 +0000 |
| Subject: | note 26251 added to function.register-shutdown-function | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38485@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:
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://www.php.net/manual/en/function.register-shutdown-function.php
http://master.php.net/manage/user-notes.php?action=edit+26251
http://master.php.net/manage/user-notes.php?action=delete+26251
http://master.php.net/manage/user-notes.php?action=reject+26251