2017 © Pedro Peláez
 

library php-error-handler

Universal error, exception and cachable fatal errors handler

image

caseycs/php-error-handler

Universal error, exception and cachable fatal errors handler

  • Friday, March 6, 2015
  • by caseycs
  • Repository
  • 3 Watchers
  • 3 Stars
  • 500 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP error handler

Common error handling with callbacks. Provides custom error message with request url, referer, session and other environment info for every error., (*1)

Example:, (*2)

SHUTDOWN Call to undefined function unexisted_function() in /Users/ikondrashov/github/php-error-handler/test/uncatchable.php:6
URL: localhost:3000/uncatchable.php
HTTP_REFERER: http://localhost:3000/uncatchable.php
SESSION: Array
(
    [a] => 5
)
POST: Array
(
    [b] => 10
)
COOKIES: Array
(
    [c] => 15
)
uniqid: 52496cfee1616

Installation via Composer, (*3)

{
    "require": {
        "caseycs/php-error-handler": "dev-master"
    },
}

````

## Usage

Basic usage:

```php
$ErrorHandler = new ErrorHandler\ErrorHandler;
$ErrorHandler->register();

Advanced usage:, (*4)

if ($_SERVER['APPLICATION_ENV'] !== 'development') {
    $ErrorHandler = new ErrorHandler\ErrorHandler;
    $ErrorHandler->register();
    $ErrorHandler->addExceptionCallback(function () {header ('HTTP/1.0 500 Internal Server Error', true, 500);});
}

Going deeper

First of all - make sure, that you have error_log value defined - both for cli and fpm (or apache) environments. Use phpinfo() for web and php -i | grep error_log for cli. Make sure, that specified file is writeable for user, which executes your cli scripts (for example using crontab) and apache/fpm., (*5)

This is very important!, (*6)

Also, make sure that display_errors equals false - this package is only for production usage., (*7)

What's our goals?, (*8)

For cli we are going to write all errors to common cli error log /var/log/php-errors-cli.php and to stderr of running script - for example from crontab * * * * * php script.php >> script.log 2>&1., (*9)

For web we are going to write all errors to common web error log /var/log/php-errors-fpm.php including environment - url, referer, get, post, cookies, session etc. Also we want to write environment for uncatchable errors - which are handled by register_shutdown_function., (*10)

Drawbacks

Fatal errors, which are not handled by set_error_handler and are caught only by register_shutdown_function appear in error log twice - first time as native php error, and second one - as our custom message with environment info. Anybody knowns how to fix this?, (*11)

The Versions

06/03 2015

dev-master

9999999-dev

Universal error, exception and cachable fatal errors handler

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php exception error handler

03/10 2013

dev-smarty2

dev-smarty2

Universal error, exception and cachable fatal errors handler

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php exception error handler