PHPackages                             kslimani/cerberus - 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. kslimani/cerberus

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

kslimani/cerberus
=================

PHP Error handler

0.2.1(10y ago)21441MITPHPPHP &gt;=5.5.0

Since Sep 4Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (13)Used By (0)

Cerberus error handler
======================

[](#cerberus-error-handler)

Simple PHP error handler.

Registering
-----------

[](#registering)

Add in `composer.json` file :

```
{
    "require": {
        "kslimani/cerberus": "~0.1.0"
    },
}
```

Usage
-----

[](#usage)

Quick setup :

```
error_reporting(-1);

use Cerberus\ErrorHandler;
use Cerberus\Handler\DebugHandler;

$errorHandler = new ErrorHandler;
$errorHandler->addHandler(new DebugHandler);
```

Cerberus come with a PSR-3 Logger Interface error handler :

```
use Cerberus\ErrorHandler;
use Cerberus\Handler\LoggerHandler;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$errorHandler = new ErrorHandler;
$logger = new Logger('errors');
$logger->pushHandler(new StreamHandler('/path/to/errors.log', Logger::NOTICE));
$errorHandler->addHandler(new LoggerHandler($logger));
```

Callable can also be added as handler :

```
use Cerberus\ErrorHandler;

$errorHandler = new ErrorHandler;
$errorHandler->addHandler(function($message, $extra) {

    // $message is a formatted error message
    // $extra is an array with error/exception details

});
```

Error/exception details
-----------------------

[](#errorexception-details)

Details array content differ according to error type.

Error :

```

[
    'displayType' : 'The error display type',
    'context'     : 'The application context',
    'memory'      : 'The memory peak usage, ONLY if debug is true',
    'trace'       : 'The error backtrace, ONLY if debug is true',
    'type'        : 'The error type, ONLY in CallableHandler',
    'message'     : 'The error message, ONLY in CallableHandler',
    'file'        : 'The error file, ONLY in CallableHandler',
    'line'        : 'The error line, ONLY in CallableHandler',
]

```

Exception :

```

[
    'displayType' : 'The error display type',
    'exception'   : 'The exception object',
    'memory'      : 'The memory peak usage, ONLY if debug is true',
    'code'        : 'The http status code, ONLY if instance of HttpExceptionInterface',
]

```

Note : `HttpExceptionInterface` refer to `Symfony\Component\HttpKernel\Exception\HttpExceptionInterface`.

Error handler priority
----------------------

[](#error-handler-priority)

Error handlers are ordered by priority (from higher to lower values).

The first added handler get a priority value of 10, the second is 11, etc ...

Priority can be changed with `setPriority()` method and must be set BEFORE adding handler.

- `DebugHandler` default priority value is `0` (last handler)
- `LoggerHandler` default priority value is `100` (first handler)
- `NewRelicHandler` default priority value is `95` (after LoggerHandler)

Silex integration example
-------------------------

[](#silex-integration-example)

This Silex example application should handle all PHP errors :

```
use Cerberus\ErrorHandler;
use Cerberus\Handler\DebugHandler;
use Cerberus\Handler\LoggerHandler;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
use Symfony\Component\HttpFoundation\Response;

// Setup autoloader

require_once '/path/to/vendor/autoload.php';

$debug = true;
error_reporting(-1);
ini_set('display_errors', 0);

// Setup error handler

$errorHandler = new ErrorHandler;
$errorHandler
    ->setDebug($debug)
    ->setThrowExceptions(false)
    ->setThrowNonFatal(false)
    ->setCallPreviousErrorHandler(false)
    ->setCallPreviousExceptionHandler(false)
;
if ($debug) {
    $errorHandler->addHandler(new DebugHandler(false));
}

$logger = new Logger('errors');
$logger->pushHandler(new StreamHandler('/path/to/errors.log', Logger::NOTICE));
$errorHandler->addHandler(new LoggerHandler($logger));

// Create and setup application

$app = new Application();

$app['debug'] = $debug;
$app['exception_handler']->disable();
$app['cerberus'] = $errorHandler;

// Register services

$app->register(new TwigServiceProvider());

// Register simple error pages service

$app['error.response'] = $app->protect(function ($code) use ($app) {
    if ($app->offsetExists('twig')) {

        // 404.html, or 40x.html, or 4xx.html, or default.html
        $templates = array(
            'errors/'.$code.'.html',
            'errors/'.substr($code, 0, 2).'x.html',
            'errors/'.substr($code, 0, 1).'xx.html',
            'errors/default.html'
        );

        return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
    } else {
        return new Response(sprintf("HTTP Error %s", $code), $code);
    }
});

// Register fatal error handler

$app['cerberus']->addHandler(function($message, $extra) use ($app) {

    if ($app['debug']) {
        return;
    }

    $app['cerberus']->emptyOutputBuffers();
    $response = $app['error.response'](500);

    return $response->send();
});

// Register application exception handler

$app->error(function (\Exception $e, $code) use ($app) {

    if (($code >= 500) && $app['debug']) {
        return;
    }

    return $app['error.response']($code);
});

// Setup routes

$app->get('/hello/{name}', function($name) use($app) {
    return 'Hello ' . $app->escape($name);
});

// Run application

$app->run();
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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 ~39 days

Recently: every ~60 days

Total

12

Last Release

3843d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7aa8239bd8e831310ca3824748e38fce5d3c705a258830b9c3e304e1a4bf805c?d=identicon)[kslimani](/maintainers/kslimani)

---

Top Contributors

[![kslimani](https://avatars.githubusercontent.com/u/1758996?v=4)](https://github.com/kslimani "kslimani (26 commits)")

---

Tags

exceptionerrorhandlercerberus

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kslimani-cerberus/health.svg)

```
[![Health](https://phpackages.com/badges/kslimani-cerberus/health.svg)](https://phpackages.com/packages/kslimani-cerberus)
```

###  Alternatives

[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[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)[baibaratsky/yii2-rollbar

Rollbar for Yii2

35130.5k](/packages/baibaratsky-yii2-rollbar)[facile-it/sentry-module

This module allows integration of Sentry Client into laminas and mezzio

19372.5k](/packages/facile-it-sentry-module)[phptek/sentry

Sentry.io integration for SilverStripe. Binds Sentry.io to SilverStripe's error &amp; exception handling subsystem.

15203.5k3](/packages/phptek-sentry)[josegonzalez/php-error-handlers

PHP Library that includes wrappers for popular error handling services

3027.1k1](/packages/josegonzalez-php-error-handlers)

PHPackages © 2026

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