tuupke/laravel-finalizer
Composer 安装命令:
composer require tuupke/laravel-finalizer
包简介
Simple package with helpers to handle execution after closed connections
README 文档
README
Laravel's implementation of finalizers (through middleware) are still synchronous with the request and will therefor increase the response-time of your application. There are many use-cases - logging for instance - for which this is not desired.
Normally speaking, standard Laravel practices dictate that a job should be used in these cases. When this is overkill, this package can be used. It provides a small wrapper around PHP's register_shutdown_function, to help with these use-cases.
Installation
Installation of this packages is done through composer.
composer require "tuupke/laravel-finalizer"
Then open config/app.php and append to the providers array:
Tuupke\Finalizer\FinalizerServiceProvider::class,
and add to the aliasses array:
'Finalizer' => Tuupke\Finalizer\FinalizerFacade::class,
Usage
From somewhere within your application you can now call: Finalizer::register($closure)) with $closure some closure executing some action. Optionally, you can provide an integer as the second parameter, which will server as the priority. The lower this priority, the earlier it is executed. When 2 closures are registered with the same priority. The closure which was registered first, will be executed first.
Example
A minimalist example which stores some contents in a file is listed below. Note that this should not be used in an actual application. When logging is required, use the Log facade.
Finalizer::register(function(){
file_put_contents('/tmp/finalizer-test', "Second String", FILE_APPEND);
}, 2);
Finalizer::register(function(){
file_put_contents('/tmp/finalizer-test', "First String\n", FILE_APPEND);
}, 1);
After a request has been executed which contained this code-block, the contents of /tmp/finalizer-test is:
First String
Second String
Use in non-Laravel applications
Strictly speaking, this package can also be used in non-Laravel PHP applications which use composer. But it is not recommended and defeats the purpose of this package. If you want, you can still use it. A minimal example is provided below.
// include composer autoload
require 'vendor/autoload.php';
// import the Finalizer Class
use Tuupke\Finalizer;
// Create a new instance of the Finalizer. The class itself does not provide late static binding (yet).
$finalizer = new Finalizer;
// register some closure.
$finalizer->register(function(){
... <YOUR CODE GOES HERE> ...
});
tuupke/laravel-finalizer 适用场景与选型建议
tuupke/laravel-finalizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.86k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tuupke/laravel-finalizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tuupke/laravel-finalizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-28