perfbase/yii3
Composer 安装命令:
composer require perfbase/yii3
包简介
Yii 3 integration for the Perfbase profiling tool.
README 文档
README
Perfbase for Yii 3
Yii 3 integration for Perfbase.
This package is a thin adapter over perfbase/php-sdk. It keeps the framework layer thin and pushes transport, extension access, and submission behavior into the shared SDK.
Scope
v1 supports:
- HTTP profiling through PSR-15 middleware
- Console command profiling through Symfony Console events
v1 does not support:
- Queue or worker profiling
- Scheduler-specific profiling
- Custom buffering or retries
- Yii-specific profiler UI
Requirements
- PHP
>=8.1 <8.5 yiisoft/yii-http^1.1yiisoft/yii-console^2.4perfbase/php-sdk^1.0- The Perfbase PHP extension installed for the target PHP runtime
Installation
composer require perfbase/yii3
Add the config provider:
return [ \Perfbase\Yii3\ConfigProvider::class, ];
Then override params as needed:
return [ 'perfbase' => [ 'enabled' => true, 'api_key' => $_ENV['PERFBASE_API_KEY'] ?? '', 'sample_rate' => 0.1, 'app_version' => '1.0.0', ], ];
Configuration
The config provider exposes this default config under params['perfbase']:
[
'enabled' => false,
'debug' => false,
'log_errors' => true,
'api_key' => '',
'api_url' => 'https://ingress.perfbase.cloud',
'sample_rate' => 0.1,
'profile_http_status_codes' => [...range(200, 299), ...range(500, 599)],
'timeout' => 10,
'proxy' => null,
'flags' => \Perfbase\SDK\FeatureFlags::DefaultFlags,
'app_version' => '',
'include' => [
'http' => ['*'],
'console' => ['*'],
],
'exclude' => [
'http' => [],
'console' => [],
],
]
Notes:
sample_ratemust be numeric between0.0and1.0profile_http_status_codesdefaults to[...range(200, 299), ...range(500, 599)]. Add codes such as404if you want to keep them, or set it to[]to disable HTTP trace submission entirely.environmentcomes fromYII_ENV, otherwiseproductionapp_versionis application-defined
HTTP Integration
HTTP profiling is middleware-based through PerfbaseHttpMiddleware.php.
Register it in your HTTP middleware pipeline:
use Perfbase\Yii3\Middleware\PerfbaseHttpMiddleware; return [ PerfbaseHttpMiddleware::class, // other middleware... ];
Behavior:
- starts profiling before delegating to the next handler
- captures response status on success
- captures exception context on failure
- HTTP traces are only submitted when the response status code is in
profile_http_status_codes - always stops profiling in
finally
HTTP attributes include:
source=httpactionhttp_methodhttp_urlhttp_status_codeuser_ipuser_agenthostnameenvironmentapp_versionphp_version
Route metadata behavior:
- route template is resolved from request attributes such as
routePattern,route, or_route - route name is resolved from
routeNameorroute_name - controller metadata is resolved from
controlleroraction http_urlexcludes query strings
Console Integration
Console profiling is wired through ConsoleProfilerSubscriber.php, which subscribes to Symfony Console events used by Yii3 console packages.
Register the subscriber with your event dispatcher:
use Perfbase\Yii3\EventSubscriber\ConsoleProfilerSubscriber; use Symfony\Component\EventDispatcher\EventDispatcher; $dispatcher = $container->get(EventDispatcher::class); $dispatcher->addSubscriber($container->get(ConsoleProfilerSubscriber::class));
Subscribed events:
ConsoleEvents::COMMANDConsoleEvents::ERRORConsoleEvents::TERMINATE
Behavior:
- lifecycles are keyed by the input object identity
- exceptions are attached on
ERROR - exit codes are attached on
TERMINATE - lifecycle state is cleaned up even when command execution fails
Filters
Supported contexts:
httpconsole
Supported filter styles:
*.*- glob patterns such as
cache/* - regex patterns such as
/^GET \/api\//
Example:
'perfbase' => [ 'include' => [ 'http' => ['route/*', '/^GET \\/api\\//'], 'console' => ['cache/*', 'migrate'], ], 'exclude' => [ 'http' => ['debug/*'], 'console' => ['help'], ], ],
Error Handling
The adapter is fail-open:
- SDK init failures degrade to a no-op
- missing extension degrades to a no-op
- submit failures do not break request or command execution
Behavior:
debug=false: swallow and optionally log errorsdebug=true: rethrow adapter/runtime errors
Runtime Architecture
Primary entry points:
ConfigProvider.phpPerfbaseHttpMiddleware.phpConsoleProfilerSubscriber.php- lifecycle classes in
src/Lifecycle - support helpers in
src/Support
The adapter does not implement its own delivery layer.
Development
Verify locally with:
composer install
composer run test
composer run phpstan
Limitations
- No queue support in v1
- No scheduler-specific integration in v1
- No Yii-specific debug toolbar integration
- HTTP and console wiring must be registered explicitly in the host application
Documentation
Full documentation is available at perfbase.com/docs.
- Docs: perfbase.com/docs
- Issues: github.com/perfbaseorg/yii3/issues
- Support: support@perfbase.com
License
Apache-2.0. See LICENSE.txt.
perfbase/yii3 适用场景与选型建议
perfbase/yii3 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「monitoring」 「profiling」 「apm」 「yii3」 「Perfbase」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 perfbase/yii3 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 perfbase/yii3 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 perfbase/yii3 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Quick profiling of your code for Laravel
A Symfony bundle for chameleon-system/sanitycheck
Elastic APM bundle
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Excimetry PHP package. Bridge between ext-eximer and open telemetry
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-04-08