I created a terminable middleware that sends a request to Google Analytics. One of the attributes I'm sending is server response time. Here is how I do it:
In \App\Http\KernelI add SendAnalyticsmiddleware:
class Kernel extends HttpKernel {
...
protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
...
'App\Http\Middleware\SendAnalytics',
];
}
And the middleware SendAnalyticslooks like this:
class SendAnalytics implements TerminableMiddleware {
protected $startTime;
public function __construct() {
$this->startTime = microtime(true);
}
public function handle($request, Closure $next) {
return $next($request);
}
public function terminate($request, $response) {
$responseTime = microtime(true) - $this->startTime;
dd($responseTime);
}
}
But it always shows 0.0. What would be the right way to show server response time?
source
share