PHPackages                             tekintian/sentry9-php - 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. tekintian/sentry9-php

ActiveLibrary

tekintian/sentry9-php
=====================

Sentry9 PHP 可视化日志管理系统,支持 php5.3--php8.2版本, 支持 tp5, tp8, ci, yii2, laravel等PHP框架, 可以集成到框架中,也可直接使用, sentry raven thinkphp8适配, tp8 sentry 日志管理工具, sentry9 sdk for php8,php7,

2.0.1(1y ago)112BSD-3-ClausePHPPHP ^5.3|^7.0|^8.0

Since Dec 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/tekintian/sentry9-php)[ Packagist](https://packagist.org/packages/tekintian/sentry9-php)[ Docs](https://github.com/tekintian/sentry9-php)[ RSS](/packages/tekintian-sentry9-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Sentry日志管理系统 Sentry8.x sentry9.x SDK for php8.x
===============================================

[](#sentry日志管理系统-sentry8x-sentry9x-sdk-for-php8x)

Sentry 是一个开源的错误报告平台, 可以帮助开发者快速定位线上问题, 并提供详细的错误信息, 帮助开发者快速定位问题.

Sentry9.x 官方已经于2021年12月15日停止维护, sentry9.x的官方的SDK最高只支持 php7.4, 现在的PHP8直接不支持, 由于目前PHP8已经是主流, 故有了这个可以再Sentry9.x/8.x中使用的 sentry SDK.

**本SDK特点,支持php8.x , 简洁安全, 不依赖第三方类库!**

Sentry PHP 可视化日志管理系统,支持 php5.3以上版本, 支持 php7.x php8.x, 可以集成到市面上大部分的PHP框架中,也可直接使用.

为何还要使用Sentry8/9.x?
------------------

[](#为何还要使用sentry89x)

因为这个版本的内存占用非常小, 低配置的机器也可以部署sentry8.x,9.x使用, docker方式部署后总计占用内存情况 sentry8.x 3个服务总计占用内存不到500M, sentry9.x 3个服务总计占用内存不到700M

PHP集成 sentry 通用方法:
------------------

[](#php集成-sentry-通用方法)

1. 项目跟目录执行命令 composer require tekintian/sentry9-php

```
#  采用autoload.php自动载入方式加载 Sentry
require_once  __DIR__ . 'vendor/autoload.php';
```

2. 在你的入口文件中增加

```
//$client_url 为你的sentry服务端分配的客户端URL
require __DIR__ . '/vendor/autoload.php';
// 注意这里的位置需要再异常代码之前加载
$sentry = \Sentry9\Sentry::listen('https://abc4e0db14bd4d599290b783ce9ddebe@sentry.tekin.cn/2');

try {
    // 这里是你的业务代码
    // 比如:
    $a = 1 / 0;
} catch (Exception $e) {
    // 记录异常信息
    $sentry->captureException($e);
}

// 手动记录异常信息
$sentry->captureMessage("Hello message from Sentry client!");
```

thinkphp5/ tp6 sentry9配置步骤
--------------------------

[](#thinkphp5-tp6-sentry9配置步骤)

tp8默认使用的就是composer来管理第三方包, 所以直接使用 composer 来安装 sentry9 即可.

1. 安装 sentry9 包

```
# 安装 sentry9 包
composer require "tekintian/sentry9-php"
```

2. 修改tp8配置文件,增加SENTRY配置项目

在配置文件 config.php 中增加 sentry9 配置项目

```
return [
	// 其他配置信息 .......
	//SENTRY Raven Log日志可视化日志管理系统
	'sentry9' => [
		// 是否启用 TRUE 启用; FALSE  禁用
		'is_enable' => TRUE,
		// Sentry 项目配置中的客户端URL
		// sentry8
		//'client_url' => 'http://xxxxxxxxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxx@sentry.tekin.cn/1',
		// sentry9
		'client_url' => 'http://xxxxxxxxxxxxxxxxxxxxxxxxxx@sentry.tekin.cn/1',
	],
]
```

3. 在 index.php 入口文件的最后增加一下代码

```
if (config('sentry9.is_enable')) {
	// 使用tp助手函数从 thinkphp5的配置文件中获取 sentry raven url地址
	$client_url = config('sentry9.client_url');

	// sentry日志监听开启, 如果不需要配置开关,可以直接将下面这段放到你想要的地方即可.
	$sentry = \Sentry9\Sentry::listen($client_url);
	// 这样你就可以在你的项目中使用了.  也可以直接使用这里的全局变量 $sentry->handleException($exception);   来记录日志. 详情见demo.php  文件.
}
```

thinkphp8 tp8 sentry9配置步骤
-------------------------

[](#thinkphp8-tp8-sentry9配置步骤)

tp8的默认使用的就是composer来管理第三方包, 所以直接使用 composer 来安装 sentry9 即可. 同时tp8和tp5的配置方式不太一样, 这里我们直接使用自定义异常类来处理Sentry的异常.

1. 安装 sentry9 包

```
# 安装 sentry9 包
composer require "tekintian/sentry9-php"
```

2. 创建自定义异常类 位置 app\\common\\exception 目录下创建 Sentry.php 文件

```
