phpperftools/buggregator-collector

Xhprof buggregator 收集器

dev-main 2024-07-07 22:26 UTC

This package is auto-updated.

Last update: 2024-09-07 22:55:10 UTC


README

这是一个简单、框架无关的库,用于收集和持久化Xhprof(兼容)配置文件到 buggregator

使用方法

对于使用 guzzle 的基本用法,请将以下内容添加到主文件中

<?php
use PhpPerfTools\Buggregator\Collector;
use PhpPerfTools\Buggregator\Driver\Buggregator;

Collector::startAndRegisterShutdown(
    "app-name", 
    new Buggregator(
        'hostname', // for example, defined in docker-compose, please include port, by default :8000 
        new \GuzzleHttp\Client(),
        new \Http\Factory\Guzzle\RequestFactory(),
        new \Http\Factory\Guzzle\StreamFactory()
    ),
);

或在项目中使用容器时

<?php
use PhpPerfTools\Buggregator\Collector;
use PhpPerfTools\Buggregator\Driver\Buggregator;
use PhpPerfTools\Buggregator\Driver\Factory;

Collector::startAndRegisterShutdown(
    "app-name", 
    Factory::getWithContainer(
        $di, // container
        Buggregator::class, // class to create 
        ['hostname'=>'hostname'] // parameters used in driver constructor
    )
);

它将开始分析并注册一个关闭函数以提交配置文件。如果您想手动提交配置文件,请使用 Collector::start,将实例分配给变量并调用 $collector->submit(true); 如此

<?php
use PhpPerfTools\Buggregator\Collector;
use PhpPerfTools\Buggregator\Driver\Buggregator;

// init with static::start or just create an instance and call ->startProfile
$collector = Collector::start(
    "app-name", 
    new Buggregator(
        'hostname', // for example, defined in docker-compose, please include port, by default :8000 
        new \GuzzleHttp\Client(),
        new \Http\Factory\Guzzle\RequestFactory(),
        new \Http\Factory\Guzzle\StreamFactory()
    )
);

// your code here

$collector->submit(true);

为什么选择 Buggregator

我找到的所有库都是针对特定框架的(要么是中间件,要么是laravel或symfony特定),但这个库可以在没有任何框架的情况下工作。当使用非主流框架时非常有用。选项

new Buggregator(
    Psr\Http\Client\ClientInterface::class,
    Psr\Http\Message\RequestFactoryInterface::class,
    Psr\Http\Message\StreamFactoryInterface::class,
    'host',
    'path', // default: '/api/profiler/store',
    'app-name', // app name used in UI
    'tags'=> [], // list of tags
    'schema' => 'http' // By default, buggregator is used on the local dev machine, so http is enough. If you use a shared instance, you might wish to use https.
);