Skip to main content
Integrations

Yii 1.1 Integration

The Perfbase Yii 1.1 package provides automatic profiling for HTTP requests and console commands in legacy Yii 1.1 applications.

Installation

Install the Perfbase PHP extension first. This is what does the actual profiling:

bash -c "$(curl -fsSL https://cdn.perfbase.com/install.sh)"

Then install the Yii 1 package:

composer require perfbase/yii1

Configuration

Register the component in your application config and add it to the preload array so it attaches event handlers before the first request:

// protected/config/main.php
'preload' => ['perfbase'],
'components' => [
    'perfbase' => [
        'class' => 'Perfbase\Yii1\PerfbaseComponent',
        'enabled' => true,
        'api_key' => 'your-api-key',
    ],
],

The same config works in console.php for console command profiling.

Important: The preload entry is required. Without it, the component initializes lazily and misses the onBeginRequest event.

All options

KeyTypeDefaultDescription
enabledboolfalseMaster on/off switch. Requires api_key to be set.
api_keystring''Your project API key. Required.
api_urlstringhttps://ingress.perfbase.cloudIngestion endpoint.
sample_ratefloat0.1Fraction of requests to profile (0.0–1.0). 0.1 = 10%.
timeoutint10HTTP timeout in seconds for trace submission.
proxystring|nullnullOptional proxy URL (http, https, socks5, socks5h).
flagsintDefaultFlagsSDK feature flags bitmask. See Feature flags.
app_versionstring''Your application version, recorded on traces.
debugboolfalseWhen true, profiling errors are thrown instead of silently logged.
log_errorsbooltrueLog profiling errors via error_log().

Include and exclude filters

Control which routes and commands are profiled:

'perfbase' => [
    // ...
    'include' => [
        'http' => ['*'],                    // All routes (default)
        'console' => ['*'],                 // All commands (default)
        'cron' => [],                       // No cron classification (default)
    ],
    'exclude' => [
        'http' => ['/health'],
        'console' => [],
        'cron' => [],
    ],
],

Pattern types

  • Glob patterns: /site/*, migrate* (matched via fnmatch())
  • Regex patterns: /^GET \/api\// (wrapped in forward slashes)
  • Catch-all: * or .* matches everything

HTTP patterns are tested against: the request path, the resolved route, {METHOD} {path}, {METHOD} {route}, and the raw route string.

Console patterns are tested against the full command string (e.g., migrate/up) and the first segment (e.g., migrate).

HTTP profiling

HTTP requests are profiled automatically via Yii 1 application events. The component attaches to onBeginRequest, onEndRequest, onException, and onError.

For web applications (CWebApplication), the route is resolved via Yii’s URL manager ($app->getUrlManager()->parseUrl()), giving you clean routes like /site/index rather than raw URLs.

Each request gets a span named http.{METHOD}.{route} (e.g., http.GET./site/index, http.POST./user/login).

Automatic attributes

AttributeSource
hostnamegethostname()
php_versionPHP version
environmentYII_ENV constant or production
app_versionConfig value
sourcehttp
actione.g., GET /site/index
http_methodRequest method
http_urlHost + path (no query string)
http_status_codeResponse status code
user_ipClient IP address
user_agentUser agent string
user_idYii user ID (if authenticated and not guest)

Console command profiling

Console commands (CConsoleApplication) are profiled automatically using the same event mechanism. The command name is extracted from argv; for example, yiic migrate up becomes migrate/up.

Each command gets a span named console.{command} (e.g., console.migrate/up). Exit code is recorded as an attribute (0 for success, 1 if an exception or error occurred).

Cron profiling

Cron is a classified sub-context of console profiling. By default, no commands are treated as cron; the include.cron list is empty.

To classify specific commands as cron jobs, add them to the cron include list:

'include' => [
    'cron' => ['cleanup/*', 'report/*'],
],

When a console command matches the cron include patterns, it uses source = 'cron' instead of source = 'console', and the span is named cron.{command} (e.g., cron.cleanup/old-records). This makes it easy to filter cron traces separately in the dashboard.

Sample rate

The sample rate controls what fraction of requests are profiled:

'sample_rate' => 1.0,    // Profile everything (development)
'sample_rate' => 0.1,    // 10% of requests (production)
'sample_rate' => 0.01,   // 1% of requests (high-traffic)

When a request isn’t sampled, no profiling overhead is incurred.

Error handling

Profiling never crashes your application. In production (debug: false), all profiling errors are caught and optionally logged via error_log(). In development (debug: true), errors are thrown so you can catch configuration issues early.

If the Perfbase PHP extension is not installed, the component detects this gracefully and silently disables profiling.

Using the SDK directly

Access the SDK through the component for manual attribute setting:

$client = Yii::app()->perfbase->getClientProvider()->getClient();
if ($client) {
    $client->setAttribute('tenant', $tenantSlug);
}

See the PHP SDK docs for the full API reference.