perfbase/yii2
Composer 安装命令:
composer require perfbase/yii2
包简介
Yii 2 integration for the Perfbase profiling tool.
README 文档
README
Perfbase for Yii 2
Yii 2 integration for Perfbase.
This package is a thin adapter over perfbase/php-sdk. Framework wiring lives here; transport and extension access stay in the shared SDK.
Scope
v1 supports:
- HTTP request profiling
- Console command profiling
v1 does not support:
- Queue profiling
- Scheduler-specific profiling
- Custom buffering or delivery layers
- Yii-specific profiler panels
Requirements
- PHP
>=7.4 <8.5 - Yii2
^2.0.45 perfbase/php-sdk^1.0- The Perfbase PHP extension installed for the target PHP runtime
Installation
composer require perfbase/yii2
Register the component and bootstrap it in your application config:
return [ 'bootstrap' => ['perfbase'], 'components' => [ 'perfbase' => [ 'class' => \Perfbase\Yii2\PerfbaseComponent::class, 'enabled' => true, 'api_key' => getenv('PERFBASE_API_KEY') ?: '', 'sample_rate' => 0.1, 'app_version' => '1.0.0', ], ], ];
The same component can be registered in web and console app configs.
Configuration
[
'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.environmentis derived fromYII_ENV, otherwiseproductionapp_versionis application-defined
HTTP Profiling
HTTP profiling is attached through Yii2 application events:
EVENT_BEFORE_ACTIONcreates and starts the HTTP lifecycleEVENT_AFTER_REQUESTfinalizes and submits- Yii2 error-handler state is consulted during finalization to attach exception context
Attributes include:
source=httpactionhttp_methodhttp_urlhttp_status_codeuser_ipuser_agentuser_idwhen Yii user state is available and authenticatedhostnameenvironmentapp_versionphp_version
Behavior details:
- action naming prefers stable route/controller identifiers
http_urlexcludes query strings- HTTP traces are only submitted when the response status code is in
profile_http_status_codes - profiling is skipped when filters fail or the extension is unavailable
Console Profiling
Console profiling is attached through the same application-level event strategy:
EVENT_BEFORE_ACTIONcreates and starts the console lifecycleEVENT_AFTER_REQUESTfinalizes and submits- the Yii2 error handler is consulted to attach exception context when present
Console attributes include:
source=consoleactionexit_codewhen Yii2 exposes one through the response object
Exit code handling is intentionally best-effort and non-invasive.
Filters
Supported contexts:
httpconsole
Supported filter styles:
*.*- glob patterns such as
site/* - regex patterns such as
/^GET \/api\//
Example:
'include' => [ 'http' => ['site/*', '/^GET \\/api\\//'], 'console' => ['cache/*', 'migrate'], ], 'exclude' => [ 'http' => ['debug/*'], 'console' => ['help'], ],
Error Handling
The adapter fails open by design:
- invalid SDK configuration becomes a no-op
- missing extension becomes a no-op
- submit failures do not break the Yii application
Behavior:
debug=false: swallow and optionally log errorsdebug=true: rethrow adapter/runtime errors
Runtime Architecture
Primary entry points:
PerfbaseComponent.phpPerfbaseBootstrap.php- lifecycle classes in
src/Lifecycle - support helpers in
src/Support
This package does not implement its own buffering, retry, or persistence layer.
Development
Verify locally with:
composer install
composer run test
composer run phpstan
Limitations
- Queue workers are out of scope for v1
- No profiler toolbar or Yii-specific UI
- Exit code capture for console commands depends on what the Yii 2 response object exposes
Documentation
Full documentation is available at perfbase.com/docs.
- Docs: perfbase.com/docs
- Issues: github.com/perfbaseorg/yii2/issues
- Support: support@perfbase.com
License
Apache-2.0. See LICENSE.txt.
perfbase/yii2 适用场景与选型建议
perfbase/yii2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「monitoring」 「profiling」 「yii2」 「apm」 「Perfbase」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 perfbase/yii2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 perfbase/yii2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 perfbase/yii2 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Quick profiling of your code for Laravel
A Symfony bundle for chameleon-system/sanitycheck
A custom URL rule class for Yii 2 which allows to create translated URL rules
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
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-04-08