定制 phpperftools/buggregator-collector 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

phpperftools/buggregator-collector

Composer 安装命令:

composer require phpperftools/buggregator-collector

包简介

Xhprof buggregator collector

README 文档

README

Simple, framework-agnostic, library to collect and persist Xhprof (and compatible) profiles in buggregator.

Usage

For basic usage with guzzle, please add this to the main file:

<?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()
    ),
);

or when using Container in your project:

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

It will start profiling and register a shutdown function to submit profiles. If you want to manually submit profiles use Collector::start, assign instance to a variable and call $collector->submit(true); like this:

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

Why Buggregator

All libraries I found were framework-specific (either a middleware, laravel or symfony specific), but this library will work without any framework. Useful when using something different from the most popular ones. Options:

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-07-07