# Laravel Vapor


Flare will work out of the box with Laravel Vapor. However, there are a few things to keep in mind when using Flare with Vapor.

In normal server setups, Flare registers a hook into PHP to send all errors and traces at the end of the request. This ensures that your application will not be slowed down by sending errors and traces to Flare.

However, in a serverless environment like Vapor, the PHP process is frozen after the request has been handled. This means that the hook that Flare registers will not be called.

Laravel Vapor solves this by executing the hook before the request is finished, which can slow down your application quite a lot.

In order to solve this issue, you can configure Flare to send traces and logs using a job on the queue instead of sending them at the end of the request. You can do this by changing the sender in your `config/flare.php` file:

```php
'sender' => [
    'class' => \Spatie\LaravelFlare\Senders\LaravelVaporSender::class,
    'config' => [],
],
```

By default, traces and logs will be sent using a job, while errors will still be sent at the end of the request. You can configure this per entity type:

```php
'sender' => [
    'class' => \Spatie\LaravelFlare\Senders\LaravelVaporSender::class,
    'config' => [
        'queue_errors' => false,  // default: false (errors sent immediately)
        'queue_traces' => true,   // default: true
        'queue_logs' => true,     // default: true
    ],
],
```

Errors stay synchronous by default so a fatal error still reports even when the queue worker is unavailable. Traces and logs are far more frequent and tolerate the small delay queued delivery introduces.

It is possible to define the connection and queue name that should be used to dispatch the job. You can do this by adding the `connection` and `queue` keys to the sender configuration:

```php
'sender' => [
    'class' => \Spatie\LaravelFlare\Senders\LaravelVaporSender::class,
    'config' => [
        'connection' => 'sqs',
        'queue' => 'flare',
    ],
],
```

If you want to configure the sender which will be called by the `LaravelVaporSender`, you can do so by adding the `sender` and `sender_config` keys to the sender configuration:

```php
'sender' => [
    'class' => \Spatie\LaravelFlare\Senders\LaravelVaporSender::class,
    'config' => [
        'sender' => \Spatie\FlareClient\Senders\CurlSender::class,
        'sender_config' => [
            'curl_options' => [
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_SSL_VERIFYPEER => 0,
            ],
        ],
    ],
],
```

## Test payloads

`php artisan flare:test` always sends test payloads synchronously, regardless of the `queue_*` flags above. This way the command can report success or failure based on Flare's actual response instead of just confirming the job was queued.

## Logging

If you have [logging](/docs/laravel/logs/introduction) enabled, set up the `flare` log channel through a `vapor` stack alongside `stderr` so Vapor's log forwarding still picks up entries even when log shipping itself is queued. The [logs introduction](/docs/laravel/logs/introduction#laravel-vapor) shows the channel configuration.
