Introduction
Flare collects errors and exceptions thrown in your PHP application and ships them to flareapp.io, together with everything we know about the moment they happened.
If you haven't installed the client yet, start with the installation guide.
How errors get to Flare
The PHP client is framework agnostic, so it doesn't hook into a global exception handler on its own. There are two ways to make errors reach Flare.
Registering the global handlers
Call registerFlareHandlers() once during bootstrap to register Flare as PHP's exception and error handler. After that, any uncaught throwable and any PHP error that matches your configured severity levels is reported automatically:
$flare->registerFlareHandlers();
If you only want one of the two, the individual methods are available as well:
$flare->registerExceptionHandler();
$flare->registerErrorHandler(E_ALL & ~E_NOTICE);
Reporting manually
When you catch a throwable yourself, hand it to Flare with reportHandled():
try {
// ...
} catch (Throwable $exception) {
$flare->reportHandled($exception);
}
Errors reported this way are marked as handled in Flare, so you can filter them out separately from unhandled crashes.
PHP errors
PHP defines two kinds of things that can go wrong: exceptions, and errors (notices, warnings, fatal errors, and so on). The Flare client wraps PHP errors into ErrorException instances and reports them the same way as exceptions.
By default, every error level is sent to Flare. You can narrow that down on the FlareConfig if you want to filter low severity noise:
$config->reportErrorLevels(E_ALL & ~E_NOTICE);
Throughout the documentation, the word "error" covers both exceptions and PHP errors.
Data collection with errors
Each error report carries a lot of contextual data on top of the stacktrace. Most of it is collected for you, and you can extend or strip it where needed. The data collection section covers every collector in detail. A few that are especially useful around errors:
- Custom context. Attach key/value data that applies to every error and log.
- Exception context. Attach context to a specific exception class.
- Identifying users. Attach the authenticated user to a report.
- Stacktrace arguments. Include the arguments passed to each frame.
- On this page
- How errors get to Flare
- Data collection with errors