# Laravel Octane

By defaults Inspector registers a shutdown function to transfer data from your application to Inspector at the end of each request lifecycle.

Since Octane runs your application in a long-running process, the data transfer must be performed at the end of the HTTP request life cycle.

So instead of using the normal `WebRequestMonitoring` middleware, you should attach to your routes the Octane specialized middleware.

### Configure the Octane middleware

Register the `InspectorOctaneMiddleware` class instead of `WebRequestMonitoring`:

#### Laravel 11

```php
use \Inspector\Laravel\Middleware\InspectorOctaneMiddleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        // routes
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Append the middleware
        $middleware->appendToGroup('web', InspectorOctaneMiddleware::class)
            ->appendToGroup('api', InspectorOctaneMiddleware::class);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();
```

#### Laravel <= 10

```php
/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        ...,
        //\Inspector\Laravel\Middleware\WebRequestMonitoring::class,
        \Inspector\Laravel\Middleware\InspectorOctaneMiddleware::class,
    ],
    
    'api' => [
        ...,
        //\Inspector\Laravel\Middleware\WebRequestMonitoring::class,
        \Inspector\Laravel\Middleware\InspectorOctaneMiddleware::class,
    ],
]
```

Now Inspector is able to recognize the end of an HTTP requests and monitor your application properly.

{% hint style="info" %}

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

{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.inspector.dev/guides/laravel/laravel-octane.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
