shutdown
云策文档标注
概述
shutdown 是一个 WordPress 动作钩子,在 PHP 执行关闭前触发,适用于需要捕获所有请求场景的“兜底”逻辑。
关键要点
- shutdown 钩子在 PHP 关闭执行前触发,由 shutdown_action_hook() 调用,并通过 register_shutdown_function() 在 wp-settings.php 中注册。
- 该钩子始终被调用,包括在致命错误、Ajax 请求或使用 exit; 或 die(); 终止请求时,适合用于日志记录等“兜底”操作。
- 注意:如果在 shutdown 动作处理程序中调用 exit;,请求会立即停止,不会调用其他 shutdown 动作处理程序。
原文内容
Fires just before PHP shuts down execution.
Source
do_action( 'shutdown' );
Changelog
| Version | Description |
|---|---|
| 1.2.0 | Introduced. |
Skip to note 2 content
Philipp Stracker
The
shutdownaction is always called, even on fatal errors, Ajax requests, and when usingexit;ordie();to terminate a running request.That makes this function perfect for a “catch-all” logic, like writing a log file.
Note: If you call
exit;inside your shutdown action-handler, the request will be instantly halted without calling other shutdown action-handlers.