Flare by Spatie
    • Error Tracking
    • Performance Monitoring
    • Logs
  • Pricing
  • Docs
  • Insights
  • Changelog
  • Back to Flare ⌘↵ Shortcut: Command or Control Enter
  • Sign in
  • Try Flare for free
  • Error Tracking
  • Performance Monitoring
  • Logs
  • Pricing
  • Docs
  • Insights
  • Changelog
    • Back to Flare ⌘↵ Shortcut: Command or Control Enter
    • Try Flare for free
    • Sign in
Flare Flare PHP PHP JavaScript JavaScript Protocol Protocol
PHP
  • Laravel
  • PHP
  • General
  • Installation
  • Integrating into a framework
  • Attribute providers
  • Application lifecycle
  • Censoring collected data
  • Ignoring collected data
  • Flare daemon
  • Errors
  • Introduction
  • Customise error report
  • Customising error grouping
  • Linking to errors
  • Logs
  • Introduction
  • Levels
  • With errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and events
  • Data Collection
  • Application info
  • Cache events
  • Console commands
  • Custom context
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Jobs and queues
  • Queries
  • Redis commands
  • Requests
  • Routing
  • Server info
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Flare Client PHP V2
  • Flare Client PHP V1

Installation

View as Markdown

Use the installation guide below to match your PHP version and initialization flow:

This guide covers every supported setup. Follow only the steps that match your project: conditional instructions start with a bold "If ..." line describing when they apply. Steps without such a line always apply. Replace YOUR-API-KEY with the project's API key. You can find it in the project settings on https://flareapp.io.

Step 1: Install the package using Composer

If your project uses PHP 8.1 or newer:

composer require spatie/flare-client-php:"^3.2"

If your project uses PHP 8.0:

composer require spatie/flare-client-php:"^1.0"

If your project uses PHP 7.1, 7.2, 7.3, or 7.4:

composer require facade/flare-client-php

Step 2: Register Flare & configure

Add this code to your project (typically in your bootstrap or entry file):

If your project uses PHP 8.1 or newer with logging and the Flare daemon:

In bootstrap.php:

require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;
use Spatie\FlareClient\FlareConfig;
use Spatie\FlareClient\Senders\DaemonSender;

$config = FlareConfig::make('YOUR-API-KEY')->useDefaults()->log()
    ->sendUsing(DaemonSender::class, ['daemon_url' => getenv('FLARE_DAEMON_URL') ?: 'http://127.0.0.1:8787']);

$flare = Flare::make($config)->start();

// Run your application

$flare->end();

If your project uses PHP 8.1 or newer with logging, without the Flare daemon:

In bootstrap.php:

require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;
use Spatie\FlareClient\FlareConfig;

$config = FlareConfig::make('YOUR-API-KEY')->useDefaults()->log();

$flare = Flare::make($config)->start();

// Run your application

$flare->end();

If your project uses PHP 8.1 or newer with the Flare daemon, without logging:

In bootstrap.php:

require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;
use Spatie\FlareClient\FlareConfig;
use Spatie\FlareClient\Senders\DaemonSender;

$config = FlareConfig::make('YOUR-API-KEY')->useDefaults()
    ->sendUsing(DaemonSender::class, ['daemon_url' => getenv('FLARE_DAEMON_URL') ?: 'http://127.0.0.1:8787']);

$flare = Flare::make($config)->start();

// Run your application

$flare->end();

If your project uses PHP 8.1 or newer without logging or the Flare daemon:

In bootstrap.php:

require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;
use Spatie\FlareClient\FlareConfig;

$config = FlareConfig::make('YOUR-API-KEY')->useDefaults();

$flare = Flare::make($config)->start();

// Run your application

$flare->end();

If your project uses PHP 8.1 or newer and you use the Flare daemon:

The Flare daemon forwards reports asynchronously so Flare delivery stays off your request path. See the Flare daemon documentation for instructions on running the daemon on Kubernetes, Docker, or a generic VPS.

If your project uses PHP 8.0:

In bootstrap.php:

require __DIR__ . '/vendor/autoload.php';

use Spatie\FlareClient\Flare;

$flare = Flare::make('YOUR-API-KEY')->registerFlareHandlers();

If your project uses PHP 7.1, 7.2, 7.3, or 7.4:

In bootstrap.php:

require __DIR__ . '/vendor/autoload.php';

use Facade\FlareClient\Flare;

$flare = Flare::register('YOUR-API-KEY')->registerFlareHandlers();

Step 3: Connect your project key

Your project key (YOUR-API-KEY) is already included in the initialization code from the previous step.

Step 4: Verify your setup

Trigger a test exception to verify everything is working. This will terminate the script with an uncaught exception, but the exception should appear in Flare:

In test.php:

throw new \Exception('This is an exception to test if the integration with Flare works.');

Great! From now on, Flare will track all errors and exceptions throughout your application.

In the next pages we will discuss the different configuration options available to you, methods you can call on the config object will always be using the $config variable, methods that should be called on the Flare object will be using the $flare variable.

Using defaults

During these docs we'll often talk about features being enabled by default this is enabled by calling the useDefaults method on the Flare config instance. This method will enable a sensible set of features that should work for most applications. If you want to disable all default features, you can simply omit the useDefaults call and enable features manually.

Setting the application root path

We recommend that you set the application root path. This will help Flare determine the correct file paths in your stack traces.

$config->applicationPath('/path/to/your/application/root');

Using an older PHP version?

The current spatie/flare-client-php package supports PHP 8.1 and later. If you're on PHP 8.0 or below, older clients are available.

In the past we've had multiple clients for framework agnostic PHP applications without support for performance monitoring. While these packages are still available, we recommend using the new flare-client-php package for all new projects:

  • spatie/flare-client-php v2: supports PHP 8.2 and later
  • spatie/flare-client-php v1: supports PHP 8.0 and later
  • facade/flare-client-php v1: supports PHP 7.1 until 8.0

Using Ignition?

If you're maintaining an older project that already uses Ignition, you can keep that setup in place while you work on the app.

For older projects where you still need to add Flare, we recommend installing the standalone spatie/flare-client-php or facade/flare-client-php package directly instead of adding Ignition.

Upgrading

You can find more information about the flare-client-php upgrade from v1 to v2 here.

Integrating into a framework

On this page

  • Using an older PHP version?
  • Using Ignition?
  • Upgrading

Catch errors and fix slowdowns with Flare, the full-stack application monitoring platform for Laravel, PHP & JavaScript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Insights
  • Newsletter
  • Changelog
  • Documentation
  • Affiliate program
  • uptime status badge Service status
  • Terms of use
  • DPA
  • Privacy & cookie Policy
Made in by Spatie logo
Flare