PHPackages                             gaowei-space/error-handler - 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. gaowei-space/error-handler

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

gaowei-space/error-handler
==========================

ErrorHandler is used to catch all php runtime errors and supports reporting to monolog or sentry.

1.2.0(3y ago)141MITPHPPHP ^7.2|^8.0

Since May 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/gaowei-space/error-handler)[ Packagist](https://packagist.org/packages/gaowei-space/error-handler)[ Docs](https://github.com/gaowei-space/error-handler)[ RSS](/packages/gaowei-space-error-handler/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (6)Dependencies (4)Versions (7)Used By (0)

🎯 Error-Handler
===============

[](#-error-handler)

[中文](https://github.com/gaowei-space/error-handler/blob/main/README.md) | [English](https://github.com/gaowei-space/error-handler/blob/main/README_EN.md)

[![GitHub branch checks state](https://camo.githubusercontent.com/e1840e7e1213d495ba3685e44620086fcbcc939173eed84450c97e8c726331e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636865636b732d7374617475732f67616f7765692d73706163652f6572726f722d68616e646c65722f6d61696e)](https://camo.githubusercontent.com/e1840e7e1213d495ba3685e44620086fcbcc939173eed84450c97e8c726331e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636865636b732d7374617475732f67616f7765692d73706163652f6572726f722d68616e646c65722f6d61696e)[![Latest Release](https://camo.githubusercontent.com/fd57fdc44145745ae956b6168340cf163bc9e60f9e6f5a6a3407cc003db340fa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f67616f7765692d73706163652f6572726f722d68616e646c6572)](https://github.com/gaowei-space/error-handler/releases)[![StyleCI build status](https://camo.githubusercontent.com/d031518f433ea55e9b23f05677384136d839d51f6e44d2fcfbe23d6d3528e5b8/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3439363837353437332f736869656c64)](https://camo.githubusercontent.com/d031518f433ea55e9b23f05677384136d839d51f6e44d2fcfbe23d6d3528e5b8/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3439363837353437332f736869656c64)[![PHP Version](https://camo.githubusercontent.com/5f958a7db3b884b24cdf3c4281b0ac315a8a59cc1d20184490913b65229d2ab0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f67616f7765692d73706163652f6572726f722d68616e646c6572)](https://www.php.net/)[![License](https://camo.githubusercontent.com/1a1f37a6327b4b47c09c4446bb0c089c5dafcb584b039e389ab970e43865f595/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f67616f7765692d73706163652f6572726f722d68616e646c6572)](https://github.com/gaowei-space/error-handler/LICENSE)

[Error-Handler](https://github.com/gaowei-space/error-handler) 是用于捕获PHP项目运行期间的各类异常错误，支持通过**monolog**或者**sentry**进行错误上报.

> 与Sentry官方的加载方式相比，该包只在捕获到异常时才进行实例化并报告异常，所以消耗的服务器资源更少，这也是这个包诞生的原因。

安装
--

[](#安装)

```
composer require gaowei-space/error-handler
```

使用
--

[](#使用)

### 1. sentry

[](#1-sentry)

```
$options = [
    'report_level'   => E_ALL,
    'display_errors' => true,
    'handler'        => 'sentry', // sentry or logger
    'sentry_options' => [
        'dsn'          => 'http://0c2f5aaca4a14eaf958a050157843090@sentry.yoursentrysite.com/3',
        'environment'  => 'test',
        'sample_rate'  => 1,
        'http_timeout' => 0.5,
    ],
    'scope_user' => [
        'id'       => 10,
        'username' => '丹',
    ],
    'scope_tags' => [
        'game_role' => '菜鸟',
    ],
];
ErrorHandler::init($options);
```

- [sentry 文档](https://docs.sentry.io/platforms/php/)
- [sentry 参数配置](https://docs.sentry.io/platforms/php/configuration/options/)

### 2. monolog

[](#2-monolog)

```
$logger = new Logger("errors");
$logger->pushHandler(new StreamHandler(sprintf('%s/log/errors_%s.log', __DIR__, date('Ymd')), Logger::DEBUG, true, 0666));

$options = [
    'report_level'   => E_ALL,
    'display_errors' => true,
    'handler'        => 'logger', // sentry or logger
    'logger'         => $logger,
];
ErrorHandler::init($options);
```

测试
--

[](#测试)

### 1. 安装开发扩展包

[](#1-安装开发扩展包)

```
composer require gaowei-space/error-handler --dev

```

### 2. 复制配置文件

[](#2-复制配置文件)

```
cp examples/.env.example examples/.env

```

### 3. 编辑配置文件

[](#3-编辑配置文件)

```
SENTRY_DSN = "http://0c2f5aaca4a14eaf958a050157843090@sentry.yoursentrysite.com/3"

```

### 4. 运行测试代码

[](#4-运行测试代码)

```
// monolog
php examples/Monolog.php
// sentry
php examples/Sentry.php
```

与Sentry官方实例化进行对比如下
------------------

[](#与sentry官方实例化进行对比如下)

```
$options = [
    'report_level'   => E_ALL, // error report level
    'display_errors' => true, // prite errors
    'handler'        => 'sentry', // sentry or logger
    'sentry_options' => [
        'dsn'          => 'http://0c2f5aaca4a14eaf958a050157843090@sentry.yoursentrysite.com/3', // sentry website dsn
        'environment'  => 'test',
        'sample_rate'  => 1, // report rate, float range 0-1
        'http_timeout' => 0.5,
    ],
];

本扩展包:
ErrorHandler::init($options); // 耗时: 0.001616

Sentry 官方:
\Sentry\init($options['sentry_options']); // 耗时: 0.146600

```

授权许可
----

[](#授权许可)

本项目采用 MIT 开源授权许可证，完整的授权说明已放置在 [LICENSE](https://github.com/gaowei-space/error-handler/blob/main/LICENSE) 文件中。

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~64 days

Recently: every ~79 days

Total

6

Last Release

1178d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10205742?v=4)[will-gao](/maintainers/gaowei-space)[@gaowei-space](https://github.com/gaowei-space)

---

Top Contributors

[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (2 commits)")[![gaowei-space](https://avatars.githubusercontent.com/u/10205742?v=4)](https://github.com/gaowei-space "gaowei-space (1 commits)")

---

Tags

composer-packagecrash-reportingerror-monitoringerror-reportingphp-librarysentry

### Embed Badge

![Health badge](/badges/gaowei-space-error-handler/health.svg)

```
[![Health](https://phpackages.com/badges/gaowei-space-error-handler/health.svg)](https://phpackages.com/packages/gaowei-space-error-handler)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[illuminate/log

The Illuminate Log package.

6225.3M623](/packages/illuminate-log)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[laravel/nightwatch

The official Laravel Nightwatch package.

36210.1M36](/packages/laravel-nightwatch)

PHPackages © 2026

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