Laravel 5 关机功能替代

2021-12-18 00:00:00 php laravel laravel-5

由于 Application::shutdown() 函数已被删除,我正在寻找替代方法来帮助我确定 Laravel 已完成,在运行结束前一刻.另一件可以帮助我的事情是 Laravel 使用的最后一个函数.

Since Application::shutdown() function has removed, I'm looking for alternative which will assist me determine Laravel has finished, a moment before the end of the running. Another thing which can assist me, is the last function that Laravel use.

注意:我不需要注册回调,我正在构建一个需要了解 Laravel 运行情况的分析工具.

Note: I don't need to register a callback, I'm building a profiling tool which need to understand Laravel done its run.

谢谢.

推荐答案

在 Laravel 5 中 shutdown() 已被 可终止中间件

In Laravel 5 the shutdown() has been replaced by Terminable Middleware

这是在 HTTP 响应已经发送到浏览器之后 运行的中间件.

This is middleware that is run after the HTTP response has already been sent to the browser.

use IlluminateContractsRoutingTerminableMiddleware;

class MyProfiler implements TerminableMiddleware {

    public function handle($request, $next)
    {
        return $next($request);
    }

    public function terminate($request, $response)
    {
        // Do your profiling here
    }

}

相关文章