Search by

perfbase / yii1

BenPoulson

Yii 1.1 integration for the Perfbase profiling tool.

Package info

github.com/perfbaseorg/yii1

pkg:composer/perfbase/yii1

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.2.0 2026-11-23 17:24 UTC

This package is auto-updated.

Last update: 2026-11-23 17:25:13 UTC


README

Perfbase

Perfbase for Yii 1.1

Yii 1.1 integration for Perfbase.

Packagist Version License CI PHP Version Yii Version

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.

Scope

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.

Requirements

  • PHP >=7.4 <8.7
  • Yii 1.1.x
  • perfbase/php-sdk ^1.9
  • The native Perfbase PHP extension available to the target PHP runtime

On PHP 8.5+, Yii 1.1.32 itself still uses casts that PHP reports as E_DEPRECATED (for example (double) in CHttpRequest), and Yii's error handler ends the request on any reported error. Exclude E_DEPRECATED from error_reporting in Yii 1.1 apps running on PHP 8.5+. This package does not raise deprecations of its own.

Installation

composer require perfbase/yii1

Register 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.

Configuration

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' => ['shell'],
        'cron' => [],
    ],
]

Config notes:

  • Values may be strings, as read from environment variables: 'true' / 'false' / '1' / '0' for booleans, digit strings for timeout and flags, and empty strings for "not set" (proxy, api_url, app_version).

  • enabled controls Perfbase profiling, not Yii component loading.

  • include.cron is empty by default. That means console commands profile as source=console unless you explicitly classify them as cron.

  • sample_rate must be numeric and between 0.0 and 1.0.

  • profile_http_status_codes defaults to [...range(200, 299), ...range(500, 599)]. Add codes such as 404 if you want to keep them, or set it to [] to disable HTTP trace submission entirely.

  • app_version is application-defined.

  • environment is derived from YII_ENV when available, otherwise production.

  • If exclude is set without a console key, the default console excludes still apply.

Feature Flags

flags is passed to the Perfbase extension. The default, FeatureFlags::DefaultFlags, enables everything except per-function CPU time and memory allocation tracking. 0 (FeatureFlags::AllFlags) enables every feature except the opt-in flags UsePreciseClock and TrackCpuTime.

Available flags (combine with |): UsePreciseClock, TrackCpuTime, TrackMemoryAllocation, TrackExceptions, TrackFileCompilation, TrackPdo, TrackMongodb, TrackElasticsearch, TrackCaches, TrackHttp, TrackMail, TrackFileOperations, TrackProc, TrackProcessList, TrackErrors, TrackMagicMethods, TrackOpcache, TrackStreams (PHP 8.6+).

'flags' => \Perfbase\SDK\FeatureFlags::DefaultFlags | \Perfbase\SDK\FeatureFlags::TrackCpuTime,

HTTP Profiling

HTTP profiling is attached through Yii 1.1 application events:

  • onBeginRequest starts the HTTP lifecycle
  • onException and onError attach exception context
  • onEndRequest finalizes and submits

Attributes include:

  • source=http
  • action
  • http_method
  • http_url
  • http_status_code
  • user_ip
  • user_agent
  • user_id when the application loaded the user component during the request and the user is authenticated
  • hostname
  • environment
  • app_version
  • php_version

Behavior details:

  • action prefers a stable Yii route and never contains the query string
  • http_url is the full request URL including the query string (see below)
  • HTTP traces are only submitted when the response status code is in profile_http_status_codes
  • response status defaults to 200 when Yii has not set a more specific status
  • the profiler never loads the user component itself, because loading CWebUser opens the PHP session

URL and Privacy Behavior

http_url keeps the query string, because it often identifies the operation (/index.php?r=site/page), but the values of credential-looking parameters are replaced with REDACTED by the PHP SDK's UrlSanitizer: names such as token, access_token, password, api_key, signature, nonce, PHPSESSID and email. User info and fragments are dropped.

https://example.com/ajax.php?method=example&token=secret

becomes:

https://example.com/ajax.php?method=example&token=REDACTED

Console and Cron Profiling

Console profiling also uses application lifecycle hooks:

  • onBeginRequest resolves the console command from $_SERVER['argv']
  • onException and onError mark failures
  • onEndRequest finalizes and submits

Console behavior:

  • normal console commands use source=console
  • commands matching include.cron and not matching exclude.cron use source=cron
  • the span name is cli for console commands and cron for cron commands; the command (command/action) is in the action attribute. Earlier releases named this span artisan.
  • the interactive shell command is excluded by default, because it would keep one trace open for the whole session; Yii 1.1 has no built-in queue worker, so add any long-running worker or daemon commands of your own to exclude.console
  • exit code handling is best-effort and intentionally thin:
    • 0 on normal completion
    • 1 on uncaught exception or error paths

Cron is just a classification of console commands. There is no scheduler-specific integration in v1.

Filters

Each context supports include/exclude filters:

  • http
  • console
  • cron

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' => ['shell', 'help'],
    'cron' => ['schedule/test'],
],

Error Handling

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, or the SDK throws while submitting, the application continues

Error mode behavior:

  • debug=false: swallow errors and optionally log them
  • debug=true: rethrow Perfbase adapter/runtime errors

Runtime Architecture

The package stays intentionally thin:

The adapter does not implement a separate transport or persistence layer.

Development

Install and verify with:

composer install
composer run test
composer run phpstan

Documentation

Full documentation is available at perfbase.com/docs.

License

Apache-2.0. See LICENSE.txt.