gielfeldt/shutdownhandler
Composer 安装命令:
composer require gielfeldt/shutdownhandler
包简介
Shutdown Handler.
关键字:
README 文档
README
Installation
To install the ShutdownHandler library in your project using Composer, first add the following to your composer.json
config file.
{ "require": { "gielfeldt/shutdownhandler": "~1.0" } }
Then run Composer's install or update commands to complete installation. Please visit the Composer homepage for more information about how to use Composer.
Shutdown handler
This shutdown handler class allows you to create advanced shutdown handlers, that can be manipulated after being created.
Motivation
-
Destructors are not run on fatal errors. In my particular case, I needed a lock class that was robust wrt to cleaning up after itself. See "Example 2" below or examples/fatal.php for an example of this.
-
PHP shutdown handlers cannot be manipulated after registration (unregister, execute, etc.).
Example 1 - using Shutdown Handler
namespace Gielfeldt\ShutdownHandler\Example; require 'vendor/autoload.php'; use Gielfeldt\ShutdownHandler\ShutdownHandler; /** * Simple shutdown handler callback. * * @param string $message * Message to display during shutdown. */ function myshutdownhandler($message = '') { echo "Goodbye $message\n"; } // Register shutdown handler to be run during PHP shutdown phase. $handler = new ShutdownHandler('\Gielfeldt\ShutdownHandler\Example\myshutdownhandler', array('cruel world')); echo "Hello world\n"; // Register shutdown handler. $handler2 = new ShutdownHandler('\Gielfeldt\ShutdownHandler\Example\myshutdownhandler', array('for now')); // Don't wait for shutdown phase, just run now. $handler2->run();
Example 2 - Ensuring object destruction
namespace Gielfeldt\ShutdownHandler\Example; require 'vendor/autoload.php'; use Gielfeldt\ShutdownHandler\ShutdownHandler; /** * Test class with destructor via Gielfeldt\ShutdownHandler\ShutdownHandler. */ class MyClass { /** * Reference to the shutdown handler object. * @var ShutdownHandler */ protected $shutdown; /** * Constructor. * * @param string $message * Message to display during destruction. */ public function __construct($message = '') { // Register our shutdown handler. $this->shutdown = new ShutdownHandler(array(get_class($this), 'shutdown'), array($message)); } /** * Run our shutdown handler upon object destruction. */ public function __destruct() { $this->shutdown->run(); } /** * Our shutdown handler. * * @param string $message * The message to display. */ public static function shutdown($message = '') { echo "Destroy $message\n"; } } // Instantiate object. $obj = new MyClass("world"); // Destroy object. The object's shutdown handler will be run. unset($obj); // Instantiate new object. $obj = new MyClass("universe"); // Object's shutdown handler will be run on object's destruction or when PHP's // shutdown handlers are executed. Whichever comes first.
For more examples see the examples/ folder.
Features
- Unregister a shutdown handler
- Run a shutdown handler prematurely
- Improve object destructors by ensuring destruction via PHP shutdown handlers
- Keyed shutdown handlers, allowing to easily deduplicate multiple shutdown handlers
Caveats
- Lots probably.
gielfeldt/shutdownhandler 适用场景与选型建议
gielfeldt/shutdownhandler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「handler」 「shutdown」 「destructor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gielfeldt/shutdownhandler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gielfeldt/shutdownhandler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gielfeldt/shutdownhandler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lazy loading for middleware and request handlers
Set Links with a specific language parameter
Bootstraps errors and handles them via reporters and renderers
PHP Error Handler module that captures and displays all throwable errors in a given format, making debugging easier and more efficient
Error handler based on Booboo with HTML and JSON support
A custom PHP string handler based on Laravel's Illuminate/Support/Str class
统计信息
- 总下载量: 77
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-07