Yii 1.1 integration for Perfbase.
This package is a thin adapter over perfbase/php-sdk. It keeps the framework layer thin, delegates transport and extension access to the shared SDK, fails open in production, and keeps action naming low-cardinality.
v1 supports:
- HTTP request profiling
- Console command profiling
- Cron profiling as a classified console sub-context
v1 does not support:
- Queue workers
- Custom buffering or retries
- Yii-specific profiler UI or debug panels
This package is positioned as a legacy-support adapter for real Yii 1.1 applications.
- PHP
>=7.4 <8.5 - Yii
1.1.x perfbase/php-sdk^1.0- The native Perfbase PHP extension available to the target PHP runtime
composer require perfbase/yii1Register the component as a preloaded application component in both your web and console configs:
return [
'preload' => ['perfbase'],
'components' => [
'perfbase' => [
'class' => \Perfbase\Yii1\PerfbaseComponent::class,
'enabled' => true,
'api_key' => getenv('PERFBASE_API_KEY') ?: '',
'sample_rate' => 0.1,
'app_version' => '1.0.0',
],
],
];Composer-based installation is required. Non-Composer Yii 1.1 applications are out of scope.
The adapter exposes this config contract:
[
'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' => ['*'],
'cron' => [],
],
'exclude' => [
'http' => [],
'console' => [],
'cron' => [],
],
]Config notes:
enabledcontrols Perfbase profiling, not Yii component loading.include.cronis empty by default. That means console commands profile assource=consoleunless you explicitly classify them as cron.sample_ratemust be numeric and between0.0and1.0.profile_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.app_versionis application-defined.environmentis derived fromYII_ENVwhen available, otherwiseproduction.
HTTP profiling is attached through Yii 1.1 application events:
onBeginRequeststarts the HTTP lifecycleonExceptionandonErrorattach exception contextonEndRequestfinalizes and submits
Attributes include:
source=httpactionhttp_methodhttp_urlhttp_status_codeuser_ipuser_agentuser_idwhen Yii user state is available and authenticatedhostnameenvironmentapp_versionphp_version
Behavior details:
actionprefers a stable Yii routehttp_urlexcludes query strings- HTTP traces are only submitted when the response status code is in
profile_http_status_codes - query parameters are intentionally not included in the primary action/span fields
- response status defaults to
200when Yii has not set a more specific status
Console profiling also uses application lifecycle hooks:
onBeginRequestresolves the console command from$_SERVER['argv']onExceptionandonErrormark failuresonEndRequestfinalizes and submits
Console behavior:
- normal console commands use
source=console - commands matching
include.cronand not matchingexclude.cronusesource=cron - span names are
console.{command}orcron.{command} - exit code handling is best-effort and intentionally thin:
0on normal completion1on uncaught exception or error paths
Cron is just a classification of console commands. There is no scheduler-specific integration in v1.
Each context supports include/exclude filters:
httpconsolecron
Supported filter styles:
*.*- glob patterns such as
cache/* - regex patterns such as
/^GET \/users/
Examples:
'include' => [
'http' => ['site/*', '/^GET \\/api\\//'],
'console' => ['cache/*', 'migrate'],
'cron' => ['schedule/*', 'jobs/run'],
],
'exclude' => [
'http' => ['debug/*'],
'console' => ['help'],
'cron' => ['schedule/test'],
],The adapter is designed to fail open:
- if SDK construction fails, profiling becomes a no-op
- if the extension is unavailable, profiling becomes a no-op
- if submission fails, the application continues
Error mode behavior:
debug=false: swallow errors and optionally log themdebug=true: rethrow Perfbase adapter/runtime errors
The package stays intentionally thin:
PerfbaseComponent.phpowns config and lazy service creationPerfbaseBootstrap.phpwires Yii application events- lifecycle classes under
src/Lifecycleset context-specific attributes PerfbaseClientProvider.phplazily builds the SDK client
The adapter does not implement a separate transport or persistence layer.
Install and verify with:
composer install
composer run test
composer run phpstanFull documentation is available at perfbase.com/docs.
- Docs: perfbase.com/docs
- Issues: github.com/perfbaseorg/yii1/issues
- Support: support@perfbase.com
Apache-2.0. See LICENSE.txt.