PHPackages                             josegonzalez/php-error-handlers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. josegonzalez/php-error-handlers

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

josegonzalez/php-error-handlers
===============================

PHP Library that includes wrappers for popular error handling services

0.1.0(8y ago)3027.1k↓44.4%2[5 issues](https://github.com/josegonzalez/php-error-handlers/issues)1MITPHPPHP &gt;=7.0

Since Dec 26Pushed 8y ago2 watchersCompare

[ Source](https://github.com/josegonzalez/php-error-handlers)[ Packagist](https://packagist.org/packages/josegonzalez/php-error-handlers)[ Docs](https://github.com/josegonzalez/php-error-handlers)[ RSS](/packages/josegonzalez-php-error-handlers/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (9)Versions (7)Used By (1)

[![Build Status](https://camo.githubusercontent.com/df926b0335d61b6f84bcd760f3e5d95600721f41e981238e86578966eec9d80e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6f7365676f6e7a616c657a2f7068702d6572726f722d68616e646c6572732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/josegonzalez/php-error-handlers)[![Coverage Status](https://camo.githubusercontent.com/1c973b05f9ae59e183640c9c578b34d8e025259a170072f1eeacf090e9e42968/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a6f7365676f6e7a616c657a2f7068702d6572726f722d68616e646c6572732e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/josegonzalez/php-error-handlers?branch=master)[![Total Downloads](https://camo.githubusercontent.com/caa0ce0bd691ca8892445bb490770406ea675ae10b33d51b0b4e7d9509f60d81/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f7365676f6e7a616c657a2f7068702d6572726f722d68616e646c6572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josegonzalez/php-error-handlers)[![Latest Stable Version](https://camo.githubusercontent.com/63baeeaa0506517f2c3638b68d39bbfa57b132bd8086c5445f45addaef8a3be6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f7365676f6e7a616c657a2f7068702d6572726f722d68616e646c6572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josegonzalez/php-error-handlers)

Error Handlers
==============

[](#error-handlers)

A package that includes wrappers for popular error handling services.

Includes an integration library for CakePHP 3.

Requirements
------------

[](#requirements)

- PHP 5.5+
- Patience

Installation
------------

[](#installation)

```
# install it
composer require josegonzalez/php-error-handlers
```

Usage
-----

[](#usage)

You can register the `Handler` class as a handler of php errors and exceptions.

```
// Create an array of configuration data to pass to the handler class
$config = [
    'handlers' => [
        // *Can* be the class name, not-namespaced
        // The namespace will be "interpolated" in such cases
        'NewrelicHandler' => [
        ],
        // Can also include the full namespace
        'Josegonzalez\ErrorHandlers\Handler\BugsnagHandler' => [
            'apiKey' => 'YOUR_API_KEY_HERE'
        ],
        // Invalid handlers will be ignored
        'InvalidHandler' => [
        ],
    ],
];

// Register the error handler
(new \Josegonzalez\ErrorHandlers\Handler($config))->register();

// Enjoy throwing exceptions and reporting them upstream
throw new \Exception('Test Exception');
```

The registered handler returns false by default. This allows you to chain error handlers such that this package can handle reporting while another library can display user-friendly error messages.

### Available Handlers

[](#available-handlers)

The following are built-in handlers with their configuration options:

- `AirbrakeHandler`:: Uses the official [airbrake php](https://github.com/airbrake/phpbrake/) package.
    - `host`: (optional | default: `api.airbrake.io`) airbrake api host e.g.: 'api.airbrake.io' or ''
    - `projectId`: (required | default: `null`)
    - `projectKey`: (required | default: `null`)
    - `appVersion`: (optional | default: `null`)
    - `environment`: (optional | default: `null`)
    - `rootDirectory`: (optional | default: `null`)
    - `httpClient`: (optional | default: `null`) which http client to use: "default", "curl", "guzzle" or a client instance
- `AtatusHandler`: Uses the `atatus` [php extension](https://www.atatus.com/docs/platforms/php).
    - `apiKey`: (optional | default: `null`)
- `BugsnagHandler`: Uses the official [bugsnag php](https://github.com/bugsnag/bugsnag-php) package.
    - `apiKey`: (required | default: `null`)
    - `defaults`: (optional | default: `null`) Your bugsnag endpoint for enterprise users
    - `endpoint`: (optional | default: `true`) If we should register our default callbacks
- `MonologStreamHandler`: Uses the [monolog StreamHandler](https://github.com/seldaek/monolog).
    - `name`: (optional | default: `error`)
    - `handlerClass`: (optional | default: `Monolog\Handler\StreamHandler`)
    - `stream`: (optional | default: `log/error.log`)
    - `level`: (optional | default: `Monolog\Logger::Warning`)
- `NewrelicHandler`: Uses the `newrelic` [php extension](https://docs.newrelic.com/docs/agents/php-agent/getting-started/new-relic-php).
- `RaygunHandler`: Uses the official [raygun php](https://github.com/MindscapeHQ/raygun4php) package.
    - `apiKey`: (required | default: `null`)
- `SentryHandler`: Uses the official [sentry php](https://github.com/getsentry/sentry-php) package.
    - `dsn`: (required | default: `null`)
    - `callInstall`: (optional | default: `false`) Whether or not to call the `install` method on the client.

### Handler and Exception Modification

[](#handler-and-exception-modification)

#### Modifying the client handler

[](#modifying-the-client-handler)

Sometimes you may find it useful to modify the client. For instance, it may be necessary to add contextual information to the given client call. To do so, you can set the `clientCallback` configuration key:

```
$config = [
    'handlers' => [
        'BugsnagHandler' => [
            'clientCallback' => function ($client) {
                // do something interesting to the client
                $client->setAppVersion('1.0.0');
                return $client;
            },
        ],
    ],
];
```

Note that the client should still respond to the existing reporting API provided by the upstream library. You may respond with a proxy library if desired, though returning the initial client is ideal.

> `$client` may be set to `null` inside of `clientCallback` if the handler is improperly configured.

#### Modifying the exception

[](#modifying-the-exception)

If necessary, it is possible to modify the exception being used within a particular handler. Changes to the exception will persist only for the duration of that particular handler call.

To do so, set the `exceptionCallback` configuration key for a particular handler:

```
$config = [
    'handlers' => [
        'BugsnagHandler' => [
            'exceptionCallback' => function ($exception) {
                // return null to skip reporting errors
                if ($exception instanceof \Error) {
                    return null;
                }
                return $exception;
            },
        ],
    ],
];
```

You may return another exception or `null`. In the latter case, the built-in handlers will skip reporting the given exception.

### Custom Handlers

[](#custom-handlers)

Each handler should implement the `Josegonzalez\ErrorHandlers\Handler\HandlerInterface`. This interface contains a single method:

```
public function handle($exception);
```

- PHP 5.x errors will be replaced with wrapper `ErrorException` instances before sent to the `handle` method.
- PHP 7.x errors extending `Throwable` will be replaced with wrapper `Josegonzalez\ErrorHandlers\Exception\PHP7ErrorException` instances before sent to the `handle` method.
- PHP Fatal errors will be replaced with wrapper `Josegonzalez\ErrorHandlers\Exception\FatalErrorException` instances before sent to the `handle` method.
- PHP Exceptions will be sent in, unmodified.

Custom handlers *should* extend the provided `Josegonzalez\ErrorHandlers\Handler\AbstractHandler` class. This gives them the ability to have configuration passed in via the provided `ConfigTrait` and custom `__construct()`.

### CakePHP Usage

[](#cakephp-usage)

> Loading the library is not necessary and will result in errors. Please follow the below instructions for cakephp-specific configurations.

You will want to setup at least the following configuration keys in your `config/app.php`:

- `Error.config`: Takes the same configuration array as you would give for normal php usage.

Next, configure the provided ErrorHandler classes in your `config/bootstrap.php`:

```
// around line 100
$isCli = PHP_SAPI === 'cli';
if ($isCli) {
    (new \Josegonzalez\ErrorHandlers\Cake\ConsoleErrorHandler(Configure::read('Error')))->register();
} else {
    (new \Josegonzalez\ErrorHandlers\Cake\ErrorHandler(Configure::read('Error')))->register();
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~108 days

Recently: every ~135 days

Total

6

Last Release

3257d ago

PHP version history (3 changes)0.0.1PHP &gt;=5.4

0.0.4PHP &gt;=5.5

0.1.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f38b500117ee9754ea7a4c56b800c8151ca0605b1715a3b2ff054aae504f7393?d=identicon)[josegonzalez](/maintainers/josegonzalez)

---

Top Contributors

[![josegonzalez](https://avatars.githubusercontent.com/u/65675?v=4)](https://github.com/josegonzalez "josegonzalez (67 commits)")

---

Tags

exceptionerrorcakephp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/josegonzalez-php-error-handlers/health.svg)

```
[![Health](https://phpackages.com/badges/josegonzalez-php-error-handlers/health.svg)](https://phpackages.com/packages/josegonzalez-php-error-handlers)
```

###  Alternatives

[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[facile-it/sentry-module

This module allows integration of Sentry Client into laminas and mezzio

19372.5k](/packages/facile-it-sentry-module)[guanguans/laravel-exception-notify

Monitor exception and report to the notification channels(Log、Mail、AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

14642.7k1](/packages/guanguans-laravel-exception-notify)[sandreu/cake-sentry

Sentry error handler plugin for CakePHP2

1640.2k](/packages/sandreu-cake-sentry)[mead-steve/mono-snag

Bugsnag integration for monolog. An abstract handler that sends messages to Bugsnag

20533.2k1](/packages/mead-steve-mono-snag)[baibaratsky/yii2-rollbar

Rollbar for Yii2

35130.5k](/packages/baibaratsky-yii2-rollbar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
