Home > Article > Backend Development > Detailed explanation of fastcgi_finish_request() function in Laravel
##fastcgi_finish_request() is provided by
php-fpm to end the connection response data early and continue to perform tasks on the backend Function, in order to perform long-term tasks or improve response speed, we can use this function for simple implementation. Of course, a better way is to use a queue.
fastcgi_finish_request() (if it exists), and then the
terminate() method will be called, which will execute the registration in sequence.
terminate() method in middleware.
routeMiddleware actually supports Terminable Middleware, so we can define a
FinishRequest middleware as follows to register for use.
<?phpnamespace App\Http\Middleware;use Closure;class FinishRequest {protected static $next;/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */public function handle($request, Closure $next){self::$next = $next;return response(['code' => 0, 'data' => [], 'msg' => '']);}/** * @param \Illuminate\Http\Request $request * @param $response */public function terminate($request, $response){call_user_func(self::$next, $request);} }
The above is the detailed content of Detailed explanation of fastcgi_finish_request() function in Laravel. For more information, please follow other related articles on the PHP Chinese website!