inspector-apm/inspector-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

inspector-apm/inspector-php

最新稳定版本:3.16.5

Composer 安装命令:

composer require inspector-apm/inspector-php

包简介

Inspector monitoring for PHP applications.

README 文档

README

Total Downloads Latest Stable Version License

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);
});

Chek out the official documentation

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.

统计信息

  • 总下载量: 1.99M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 35
  • 点击次数: 2
  • 依赖项目数: 12
  • 推荐数: 2

GitHub 信息

  • Stars: 34
  • Watchers: 1
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固