inspector-apm / inspector-php
PHP应用程序的检查器。
3.8.4
2024-09-16 09:40 UTC
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ^9.0
- dev-master
- 3.8.4
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.28
- 3.7.27
- 3.7.26
- 3.7.25
- 3.7.24
- 3.7.23
- 3.7.22
- 3.7.21
- 3.7.20
- 3.7.19
- 3.7.18
- 3.7.17
- 3.7.16
- 3.7.15
- 3.7.14
- 3.7.13
- 3.7.12
- 3.7.11
- 3.7.10
- 3.7.9
- 3.7.8
- 3.7.7
- 3.7.6
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.2
- 3.6.1
- 3.6.0
- 3.5.17
- 3.5.16
- 3.5.15
- 3.5.14
- 3.5.13
- 3.5.12
- 3.5.11
- 3.5.10
- 3.5.9
- 3.5.8
- 3.5.7
- 3.5.6
- 3.5.5
- 3.5.4
- 3.5.3
- 3.5.2
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.6
- 3.3.5
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.18
- 3.2.17
- 3.2.16
- 3.2.15
- 3.2.14
- 3.2.13
- 3.2.12
- 3.2.11
- 3.2.10
- 3.2.9
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.4.8
- 2.4.7
- 2.4.6
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.12
- 2.3.11
- 2.3.10
- 2.3.9
- 2.3.8
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.2.1
- 2.2.0
- 2.1.14
- 2.1.13
- 2.1.12
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.14
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-develop
This package is auto-updated.
Last update: 2024-09-16 09:41:30 UTC
README
在继续之前,请考虑给我们一个GitHub星标 ⭐️。谢谢!
代码执行监控,为PHP开发者打造。
需求
- PHP >= 7.2.0
安装
通过以下方式安装最新版本:
composer require inspector-apm/inspector-php
使用
要开始向Inspector发送数据,您需要一个Ingestion Key来创建Configuration
类的实例。您可以在Inspector仪表板上创建新项目以获得INSPECTOR_API_KEY
。
use Inspector\Inspector; use Inspector\Configuration; $configuration = new Configuration('YOUR_INGESTION_KEY'); $inspector = new Inspector($configuration);
所有操作都以transaction
开始。事务表示一个执行周期,它可以包含一个或多个段。
// Start an execution cycle with a transaction $inspector->startTransaction($_SERVER['PATH_INFO']);
使用addSegment
方法监控事务中的代码块。
$result = $inspector->addSegment(function ($segment) { // Do something here... return "Hello World!"; }, 'my-process'); echo $result; // this will print "Hello World!"
Inspector将实时监控您的代码执行,并在出现问题时提醒您。
自定义传输
您还可以设置自定义传输类,以个性化方式将监控数据从您的服务器传输到Inspector。
传输类需要实现\Inspector\Transports\TransportInterface
。
class CustomTransport implements \Inspector\Transports\TransportInterface { protected $configuration; protected $queue = []; public function __constructor($configuration) { $this->configuration = $configuration; } public function addEntry(\Inspector\Models\Arrayable $entry) { // Add an \Inspector\Models\Arrayable entry in the queue. $this->queue[] = $entry; } public function flush() { // Performs data transfer. $handle = curl_init('https://ingest.inspector.dev'); curl_setopt($handle, CURLOPT_POST, 1); curl_setopt($handle, CURLOPT_HTTPHEADER, [ 'X-Inspector-Key: xxxxxxxxxxxx', 'Content-Type: application/json', 'Accept: application/json', ]); curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($this->queue)); curl_exec($handle); curl_close($handle); } }
然后,您可以使用一个回调将新传输设置为Inspector
实例,该回调将接收当前配置状态作为参数。
$inspector->setTransport(function ($configuration) { return new CustomTransport($configuration); });
贡献
我们鼓励您为Inspector做出贡献!请查看有关如何进行的贡献指南。加入我们吧!
许可证
此包根据MIT许可证授权。