以前に登録されたすべてのシャットダウン関数(register_shutdown_functionを使用)をトリガーせずに(たとえば、exit()関数を使用して)phpスクリプトを終了するにはどうすればよいですか?
ありがとう!
編集:あるいは、登録されているすべてのシャットダウン機能をクリアする方法はありますか?
プロセスが SIGTERM または SIGKILL シグナルで強制終了された場合、シャットダウン関数は実行されません。
posix_kill(posix_getpid(), SIGTERM);
register_shutdown_function を直接使用しないでください。すべてのシャットダウン機能を管理し、独自の機能と enable プロパティを持つクラスを作成します。
class Shutdown {
private static $instance = false;
private $functions;
private $enabled = true;
private function Shutdown() {
register_shutdown_function(array($this, 'onShutdown'));
$this->functions = array();
}
public static function instance() {
if (self::$instance == false) {
self::$instance = new self();
}
return self::$instance;
}
public function onShutdown() {
if (!$this->enabled) {
return;
}
foreach ($this->functions as $fnc) {
$fnc();
}
}
public function setEnabled($value) {
$this->enabled = (bool)$value;
}
public function getEnabled() {
return $this->enabled;
}
public function registerFunction(callable $fnc) {
$this->functions[] = $fnc;
}
}