Laravel Octane
How to make Inspector works with Laravel Octane
Laravel Octane is an official Laravel package that supercharges your application's performance by serving your application using high-powered application servers, including Open Swoole, Swoole, and RoadRunner.
Octane bootsrap your application once, keeps it in memory, and then feeds it requests at high speeds.
Since Octane runs your application in a long running process you should flush the Inspector data programmatically at the end of the HTTP request life cycle.
You can achieve this behavior by extending the default middleware of the Inspector package to flush data in the terminate method.

Create the middleware

You can create a new middleware with command below:
1
php artisan make:middleware InspectorOctaneMiddleware
Copied!

Flush monitoring data

Copy & Paste this code into the newly created middleware:
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Inspector\Laravel\Middleware\WebRequestMonitoring;
6
7
class InspectorOctaneMiddleware extends WebRequestMonitoring
8
{
9
public function terminate($request, $response)
10
{
11
parent::terminate($request, $response);
12
13
inspector()->flush();
14
}
15
}
16
Copied!

Registering the middleware

Register the new middleware in App\Http\Kernel and comment the WebRequestMonitoring class:
1
/**
2
* The application's route middleware groups.
3
*
4
* @var array
5
*/
6
protected $middlewareGroups = [
7
'web' => [
8
...,
9
//\Inspector\Laravel\Middleware\WebRequestMonitoring::class,
10
\App\Http\Middleware\InspectorFlushMiddleware::class,
11
],
12
13
'api' => [
14
...,
15
//\Inspector\Laravel\Middleware\WebRequestMonitoring::class,
16
\App\Http\Middleware\InspectorFlushMiddleware::class,
17
],
Copied!
Now Inspector is able to recognize the end of a transaction to monitor your application properly.

No configuration is needed for artisan commands and background jobs. They continue to be monitored as usual.

Last modified 1mo ago
Copy link
Contents