定制 phpsoftbox/profiler 二次开发

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

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

phpsoftbox/profiler

Composer 安装命令:

composer require phpsoftbox/profiler

包简介

Lifecycle profiler contracts and runtime for PhpSoftBox

README 文档

README

phpsoftbox/profiler — легкое ядро профилирования lifecycle приложения.

Компонент не знает внутренности Database, ORM, Router, Container и других пакетов. Он предоставляет общий runtime API, registry collectors и хранилища trace. Каждый компонент реализует свою интеграцию самостоятельно.

Базовое использование

use PhpSoftBox\Profiler\Profiler;
use PhpSoftBox\Profiler\ProfilerRegistry;
use PhpSoftBox\Profiler\Store\FileProfilerStore;

$registry = new ProfilerRegistry();
$profiler = new Profiler(
    enabled: true,
    store: new FileProfilerStore(__DIR__ . '/local/profiler'),
    registry: $registry,
);

$profiler->startTrace('http.request', 'http');

$profiler->span('shipment.sort', function () {
    // измеряемый участок
}, tags: ['shipment_id' => 123]);

$trace = $profiler->finishTrace();

Component extensions

Компоненты регистрируют collectors через ProfilerExtensionInterface.

$registry = new ProfilerRegistry();

foreach ($extensions as $extension) {
    $extension->register($registry);
}

Пример ожидаемых extensions:

  • PhpSoftBox\Database\Profiler\DatabaseProfilerExtension;
  • PhpSoftBox\Orm\Profiler\OrmProfilerExtension;
  • PhpSoftBox\Container\Profiler\ContainerProfilerExtension;
  • PhpSoftBox\Router\Profiler\RouterProfilerExtension;
  • PhpSoftBox\Inertia\Profiler\InertiaProfilerExtension;
  • PhpSoftBox\Cache\Profiler\CacheProfilerExtension;
  • PhpSoftBox\Resource\Profiler\ResourceProfilerExtension.

HTTP middleware

use PhpSoftBox\Profiler\Middleware\ProfilerMiddleware;

$app->add(ProfilerMiddleware::class);

Middleware создает root trace http.request, добавляет X-Profile-Id и Server-Timing.

JSON API

Для dev-панели можно подключить ProfilerReportHandler:

use PhpSoftBox\Profiler\Http\ProfilerReportHandler;

$routes->get('/__profiler/api/traces', ProfilerReportHandler::class);
$routes->get('/__profiler/api/traces/{trace}', ProfilerReportHandler::class);

Handler возвращает 404, если профайлер выключен.

React debug panel

Backend должен отдать в Inertia shared props:

'profiler' => [
    'enabled'  => $profiler->enabled(),
    'trace_id' => $profiler->traceId(),
    'endpoint' => '/__profiler',
],

На frontend:

import { DebugProvider, ProfilerDebugPanel } from '@phpsoftbox/debug';

<DebugProvider profiler={page.props.profiler}>
    <App />
    <ProfilerDebugPanel />
</DebugProvider>

@phpsoftbox/debug читает report по trace_id, показывает timeline и компонентные sections: database, orm, container, router, inertia.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固