note 26251 deleted from function.register-shutdown-function by crell

From: Date: Thu, 31 Mar 2022 16:59:13 +0000
Subject: note 26251 deleted from function.register-shutdown-function by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217847@lists.php.net to get a copy of this message
Note Submitter: ---- 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.

« previous php.notes (#217847) next »