PHP Exception Tracking

Typical installation time: 3 minutes

Hi there! You've found Honeybadger's guide to PHP exception tracking. Note: if you use Laravel, go check out the Laravel Integration Guide. If not, then read on!

This guide will teach you how to install and configure the default Honeybadger for PHP client and use it to manually report errors to Honeybadger.

On this page:


First, install the honeybadger-php package via composer:

composer require honeybadger-io/honeybadger-php

Then, configure the Honeybadger client in your application:

$honeybadger = Honeybadger::new([
    'api_key' => 'abc123'

Honeybadger can report exceptions in several ways. To test that the Honeybadger client is working, try sending a custom notification:

    'title'   => 'Special Error',
    'message' => 'Special Error: a special error has occurred',

To catch exceptions in your code and report them to Honeybadger:

try {
    throw new Exception('Whoops!');
} catch (Exception $e) {
    // You can optionally include your own
    // \Symfony\Component\HttpFoundation\Request::class request.
    $honeybadger->notify($e, $app->request());

Adding Context

In Honeybadger, context is a custom array of data that's displayed with your error reports. You can add context from anywhere in your app, and it will be included automatically when reporting errors. For example, you could include the ID of the currently logged-in user:

$honeybadger->context('user_id', $this->Auth->user('id'));

See Customizing Error Reports for more info.