inspector-apm/inspector-php
Composer 安装命令:
composer require inspector-apm/inspector-php
包简介
Inspector monitoring for PHP applications.
README 文档
README
Before moving on, please consider giving us a GitHub star ⭐️. Thank you!
Code Execution Monitoring, built for PHP developers.
Requirements
- PHP >= ^8.1
Install
Install the latest version by:
composer require inspector-apm/inspector-php
Use
To start sending data to Inspector you need an Ingestion Key to create an instance of the Configuration class.
You can obtain INSPECTOR_API_KEY creating a new project in your Inspector dashboard.
use Inspector\Inspector; use Inspector\Configuration; $configuration = new Configuration('YOUR_INGESTION_KEY'); $inspector = new Inspector($configuration);
All start with a transaction. Transaction represents an execution cycle, and it can contain one or hundred of segments:
// Start an execution cycle with a transaction $inspector->startTransaction($_SERVER['PATH_INFO']);
Use addSegment method to monitor a code block in your transaction:
$result = $inspector->addSegment(function ($segment) { // Do something here... return "Hello World!"; }, 'my-process'); echo $result; // this will print "Hello World!"
Inspector will monitor your code execution in real time alerting you if something goes wrong.
Custom Transport
You can also set up a custom transport class to transfer monitoring data from your server to Inspector in a personalized way.
The transport class needs to implement \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\Model $entry) { // Add an \Inspector\Models\Model 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); } }
Then you can set the new transport in the Inspector instance
using a callback that will receive the current configuration state as parameter.
$inspector->setTransport(function (\Inspector\Configuration $configuration) { return new CustomTransport($configuration); });
Concurrent & Async Tasks
When monitoring concurrent or async tasks (e.g. using Fibers, ReactPHP, Amp, or pcntl_fork), a single
segment stack would produce incorrect parent-child relationships because tasks interleave on the shared stack.
Use fork() to create an independent Scope for each concurrent task:
$inspector->startTransaction('request'); $controller = $inspector->startSegment('controller', 'handle'); // Fork independent scopes — both capture $controller as base parent $scopeA = $inspector->fork(); $scopeB = $inspector->fork(); // Pass $scopeA and $scopeB to your async tasks // Task A (e.g. in a Fiber or child process) $scopeA->startSegment('http', 'api-call-A')->end(); // Task B (running concurrently) $scopeB->startSegment('http', 'api-call-B')->end(); // Segments in each scope maintain their own nesting hierarchy $nested = $scopeA->startSegment('database', 'query'); // parent_hash points to api-call-A ✓ $nested->end();
Each Scope has its own segment stack, so interleaving tasks never corrupt the parent-child hierarchy.
Scopes also support addSegment(), fork() (for nested forking), and getOpenSegments().
Chek out the official documentation
Agentic Integration
You can connect the Inspector library documentation to your coding assistant as a Model Context Protocol (MCP) server.
It makes it easy for tools like Claude Code, Cursor, and VS Code extensions reliably understand what Inspector client library can do, its configurations, how to use it.
Contributing
We encourage you to contribute to Inspector! Please check out the Contribution Guidelines about how to proceed. Join us!
LICENSE
This package is licensed under the MIT license.
inspector-apm/inspector-php 适用场景与选型建议
inspector-apm/inspector-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.91M 次下载、GitHub Stars 达 35, 最近一次更新时间为 2019 年 05 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「monitoring」 「inspector」 「telemetry」 「observability」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 inspector-apm/inspector-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inspector-apm/inspector-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 inspector-apm/inspector-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simplified database records management
A Symfony bundle for chameleon-system/sanitycheck
Instant support for PHP Code Sniffer, PHP CS Fixer, and PHP MD in the Artisan CLI
SoftWax Health Check Bundle for Symfony framework
A simple cli command to inspect Laravel Redis queues.
1Pilot client for Symfony
统计信息
- 总下载量: 2.91M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 34
- 依赖项目数: 14
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-31