Laravel 5 shutdown function alternative

2019-03-02 20:00发布

问题:

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.

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

Thanks.

回答1:

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

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

use Illuminate\Contracts\Routing\TerminableMiddleware;

class MyProfiler implements TerminableMiddleware {

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

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

}