perfbase/symfony
Composer 安装命令:
composer require perfbase/symfony
包简介
Symfony integration for the Perfbase profiling tool.
README 文档
README
Perfbase for Symfony
Symfony integration for Perfbase.
perfbase/symfony is the official Symfony bundle for Perfbase.
It integrates Symfony request and console lifecycles with the Perfbase PHP SDK and native extension so traces are captured and submitted with minimal application code.
Current production scope:
- HTTP request profiling
- Console command profiling
- Configurable sampling
- Include and exclude filters for HTTP and console contexts
- Fail-open runtime behavior when profiling cannot start safely
Out of scope in the current release:
- Messenger worker profiling
- Scheduler-specific instrumentation beyond normal console commands
- Symfony Web Profiler toolbar integration
- an auto-published Symfony Flex recipe
Requirements
- PHP
7.4to8.5 - Symfony
5.4to7.x perfbase/php-sdk^1.0- The Perfbase native PHP extension installed and enabled
Installation
Install the bundle:
composer require perfbase/symfony
Install the Perfbase PHP extension if it is not already available:
bash -c "$(curl -fsSL https://cdn.perfbase.com/install.sh)"
Restart PHP-FPM, Apache, RoadRunner, Swoole, or any other long-lived PHP runtime after installing the extension.
Bundle Registration
If your application uses Symfony Flex and a published Perfbase recipe is available in your environment, bundle registration can be automated.
If not, register the bundle manually in config/bundles.php:
<?php return [ // ... Perfbase\Symfony\PerfbaseBundle::class => ['all' => true], ];
Then add config/packages/perfbase.yaml:
perfbase: enabled: true api_key: '%env(PERFBASE_API_KEY)%' sample_rate: 0.1 app_version: '%env(default::PERFBASE_APP_VERSION)%'
Recommended environment variables:
PERFBASE_API_KEY=your_api_key_here PERFBASE_APP_VERSION=1.0.0
Configuration
The bundle exposes configuration under perfbase:.
perfbase: enabled: false debug: false log_errors: true api_key: '' api_url: 'https://ingress.perfbase.cloud' sample_rate: 0.1 # Defaults to every 2xx and 5xx response. Add 404 if you want not-found traces too. # profile_http_status_codes: [200, 201, 202, 204, 500, 503, 404] timeout: 10 proxy: null flags: !php/const Perfbase\SDK\FeatureFlags::DefaultFlags app_version: '' include: http: ['*'] console: ['*'] exclude: http: [] console: []
Configuration Reference
| Key | Type | Default | Purpose |
|---|---|---|---|
enabled |
bool |
false |
Enables or disables profiling globally |
debug |
bool |
false |
Re-throws profiling errors instead of failing open |
log_errors |
bool |
true |
Logs profiling errors when debug=false |
api_key |
string |
'' |
Perfbase project API key |
api_url |
string |
https://ingress.perfbase.cloud |
Receiver base URL |
sample_rate |
float |
0.1 |
Sampling rate from 0.0 to 1.0 |
profile_http_status_codes |
int[] |
200..299, 500..599 |
HTTP response status codes that should be submitted |
timeout |
int |
10 |
SDK submission timeout in seconds |
proxy |
`string | null` | null |
flags |
int |
FeatureFlags::DefaultFlags |
Perfbase extension feature flags |
app_version |
string |
'' |
Version string attached to traces |
include.http |
string[] |
['*'] |
HTTP allow-list filters |
exclude.http |
string[] |
[] |
HTTP deny-list filters |
include.console |
string[] |
['*'] |
Console allow-list filters |
exclude.console |
string[] |
[] |
Console deny-list filters |
Validation
Invalid configuration fails during Symfony config processing.
The bundle validates:
enabled: truerequires a non-emptyapi_keyapi_urlmust be a valid URLproxymust benullor a valid URLsample_ratemust be between0.0and1.0profile_http_status_codesentries must be valid HTTP status codes between100and599timeoutmust be at least1flagsmust be non-negative- filter entries cannot be empty strings
Environment and App Version
environmentis derived from Symfonykernel.environmentapp_versionis configured explicitly underperfbase.app_version
Symfony does not define a single application-version convention, so the bundle does not infer one automatically.
Example Production Configuration
perfbase: enabled: true debug: false log_errors: true api_key: '%env(PERFBASE_API_KEY)%' api_url: 'https://ingress.perfbase.cloud' sample_rate: 0.2 profile_http_status_codes: [200, 201, 202, 204, 500, 503, 404] timeout: 10 flags: !php/const Perfbase\SDK\FeatureFlags::DefaultFlags app_version: '%env(default::PERFBASE_APP_VERSION)%' include: http: - 'GET /api/*' - 'POST /checkout' console: - 'app:*' exclude: http: - 'GET /health' - '/^GET \\/_profiler/' console: - 'cache:clear'
What Gets Profiled
HTTP Requests
The bundle profiles main HTTP requests through:
kernel.requestkernel.responsekernel.exceptionkernel.terminate
Behavior:
- main requests only
- route templates are preferred for stable naming
- response status codes are attached when available
- only responses whose status code is in
profile_http_status_codesare submitted; by default that includes2xxand5xx - exception messages are attached on exception paths
- trace submission happens during terminate
HTTP attributes include:
source=httpactionhttp_methodhttp_urlhttp_status_codeuser_ipuser_agentuser_idwhen a Symfony security token exposes oneenvironmentapp_versionhostnamephp_version
Console Commands
The bundle profiles console commands through:
console.commandconsole.errorconsole.terminate
Console attributes include:
source=consoleactionexit_codeexceptionenvironmentapp_versionhostnamephp_version
Naming and Cardinality
Span names and action values are intentionally low-cardinality.
HTTP naming preference:
- Route path template such as
GET /articles/{id} - Route name
- Raw request path
Example HTTP span:
http.GET./articles/{id}
Example console span:
console.cache:clear
URL and Privacy Behavior
The bundle excludes query strings from http_url.
Example:
https://example.com/articles/42?token=secret
becomes:
https://example.com/articles/42
This is intentional. It avoids leaking signed URLs, nonces, tokens, and other high-cardinality values into trace metadata.
Filters
The bundle supports include and exclude filters for both HTTP and console profiling.
Supported pattern styles:
*or.*to match everything- glob patterns such as
admin/*orapp:* - regex patterns such as
/^GET \/health$/
HTTP matching evaluates these inputs when available:
- route path template
- route name
- request path
METHOD path- controller string
Example:
perfbase: include: http: - 'GET /api/*' - 'app_api_*' console: - 'app:*' exclude: http: - 'GET /health' - '/^GET \\/_profiler/' console: - 'cache:clear'
Failure Model
The bundle is designed to fail open.
- In normal production mode, profiling failures do not break requests or commands
- If
log_errors=true, failures are logged - If
debug=true, profiling exceptions are re-thrown
This behavior is implemented by PerfbaseErrorHandler.php
and the lazy client boot path in PerfbaseClientProvider.php.
Architecture Notes
This package is intentionally thin.
- It does not implement its own transport
- It does not implement local buffering or retries
- It does not build trace payloads itself
- It delegates extension access and submission to
perfbase/php-sdk
Primary runtime pieces:
src/PerfbaseBundle.phpsrc/DependencyInjection/Configuration.phpsrc/DependencyInjection/PerfbaseExtension.phpsrc/Profiling/AbstractProfiler.phpsrc/Lifecycle/HttpRequestLifecycle.phpsrc/Lifecycle/ConsoleCommandLifecycle.phpsrc/EventSubscriber/HttpProfilerSubscriber.phpsrc/EventSubscriber/ConsoleProfilerSubscriber.phpsrc/Support/FilterMatcher.phpsrc/Support/SpanNaming.phpsrc/Support/PerfbaseClientProvider.php
Limitations
This release does not currently provide:
- Messenger worker instrumentation
- profiling for Symfony subrequests
- request body or response body capture
- local buffering or offline delivery modes
- Symfony Web Profiler toolbar integration
If Messenger support is added later, it should be implemented as a separate lifecycle and subscriber path.
Quality and Verification
Verification commands:
composer run test
composer run phpstan
composer run lint
php fixture-app/smoke.php
The package includes:
- unit tests for config, helpers, lifecycles, and error handling
- integration tests for HTTP and console event flows
- an install-level fixture app under
fixture-app/ - GitHub Actions CI for:
- PHP
7.4+ Symfony5.4 - PHP
8.0through8.5+ Symfony5.4 - PHP
8.1through8.5+ Symfony6.4 - PHP
8.2through8.5+ Symfony7.x - fixture-app smoke verification
- PHP
Current coverage:
- methods:
80.00% - lines:
95.27%
Symfony Flex
The repository includes a recipe source under recipe/ and bundle
metadata in composer.json.
That recipe is not consumed automatically from this repository. Symfony Flex will use it only after it has been published to the Symfony recipes ecosystem or another configured recipe source.
Development
This repository is shaped as a normal publishable library:
perfbase/php-sdkis resolved from Packagistcomposer.lockis not committed- there are no monorepo-only path repositories in the package manifest
Local development:
composer install
composer run test
composer run phpstan
php fixture-app/smoke.php
Documentation
Full documentation is available at perfbase.com/docs.
- Docs: perfbase.com/docs
- Issues: github.com/perfbaseorg/symfony/issues
- Support: support@perfbase.com
License
Apache-2.0. See LICENSE.txt.
perfbase/symfony 适用场景与选型建议
perfbase/symfony 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「monitoring」 「profiling」 「apm」 「Perfbase」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 perfbase/symfony 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 perfbase/symfony 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 perfbase/symfony 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Quick profiling of your code for Laravel
A Symfony bundle for chameleon-system/sanitycheck
The bundle for easy using json-rpc api on your project
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Excimetry PHP package. Bridge between ext-eximer and open telemetry
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-04-08