PHPackages                             perfbase/yii2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. perfbase/yii2

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

perfbase/yii2
=============

Yii 2 integration for the Perfbase profiling tool.

v1.1.1(4w ago)12↓100%Apache-2.0PHPPHP &gt;=7.4 &lt;8.6CI passing

Since Apr 8Pushed 4w agoCompare

[ Source](https://github.com/perfbaseorg/yii2)[ Packagist](https://packagist.org/packages/perfbase/yii2)[ Docs](https://github.com/perfbaseorg/yii2)[ RSS](/packages/perfbase-yii2/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (5)Versions (5)Used By (0)

 [ ![Perfbase](https://camo.githubusercontent.com/a4e071fd1246cf5c68819015801139400d74b208b76a07ba8c5945d6e4ffd3ba/68747470733a2f2f63646e2e70657266626173652e636f6d2f696d672f6c6f676f2d66756c6c2e737667) ](https://perfbase.com)

### Perfbase for Yii 2

[](#perfbase-for-yii-2)

 Yii 2 integration for [Perfbase](https://perfbase.com).

 [![Packagist Version](https://camo.githubusercontent.com/f6ace874f8b1c32398f153a2dae0bde1c4a29be3f532ce688036f16f01365fde/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70657266626173652f79696932)](https://packagist.org/packages/perfbase/yii2) [![License](https://camo.githubusercontent.com/1654669b47191b6dc0458998508157c0bf81aeb5809bef227bac98fffd709407/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f70657266626173652f79696932)](https://github.com/perfbaseorg/yii2/blob/main/LICENSE.txt) [![CI](https://camo.githubusercontent.com/0700256235895b1122b526507c798ac25159792d5a1a2a561e6491bc8ef4d676/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70657266626173656f72672f796969322f63692e796d6c3f6272616e63683d6d61696e)](https://github.com/perfbaseorg/yii2/actions/workflows/ci.yml) [![PHP Version](https://camo.githubusercontent.com/1150142271e92a6b30ce3ef37f5548f25d15d1e9cd200eea972f746cc7a2c40a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e342532422d626c7565)](https://camo.githubusercontent.com/1150142271e92a6b30ce3ef37f5548f25d15d1e9cd200eea972f746cc7a2c40a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e342532422d626c7565) [![Yii Version](https://camo.githubusercontent.com/5ff3e17a859e9b5927e8e1f95c04a3ea2f0f4676f66f36527b4386645e610622/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7969692d322e782d626c7565)](https://camo.githubusercontent.com/5ff3e17a859e9b5927e8e1f95c04a3ea2f0f4676f66f36527b4386645e610622/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7969692d322e782d626c7565)

This package is a thin adapter over [`perfbase/php-sdk`](https://packagist.org/packages/perfbase/php-sdk). Framework wiring lives here; transport and extension access stay in the shared SDK.

Scope
-----

[](#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
------------

[](#requirements)

- PHP `>=7.4  ['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
-------------

[](#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_rate` must be numeric 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.
- `environment` is derived from `YII_ENV`, otherwise `production`
- `app_version` is application-defined

HTTP Profiling
--------------

[](#http-profiling)

HTTP profiling is attached through Yii2 application events:

- `EVENT_BEFORE_ACTION` creates and starts the HTTP lifecycle
- `EVENT_AFTER_REQUEST` finalizes and submits
- Yii2 error-handler state is consulted during finalization to attach exception context

Attributes include:

- `source=http`
- `action`
- `http_method`
- `http_url`
- `http_status_code`
- `user_ip`
- `user_agent`
- `user_id` when Yii user state is available and authenticated
- `hostname`
- `environment`
- `app_version`
- `php_version`

Behavior details:

- action naming prefers stable route/controller identifiers
- `http_url` excludes 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)

Console profiling is attached through the same application-level event strategy:

- `EVENT_BEFORE_ACTION` creates and starts the console lifecycle
- `EVENT_AFTER_REQUEST` finalizes and submits
- the Yii2 error handler is consulted to attach exception context when present

Console attributes include:

- `source=console`
- `action`
- `exit_code` when Yii2 exposes one through the response object

Exit code handling is intentionally best-effort and non-invasive.

Filters
-------

[](#filters)

Supported contexts:

- `http`
- `console`

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

[](#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 errors
- `debug=true`: rethrow adapter/runtime errors

Runtime Architecture
--------------------

[](#runtime-architecture)

Primary entry points:

- [`PerfbaseComponent.php`](/Users/ben/Projects/Perfbase/environment/projects/lib-yii2/src/PerfbaseComponent.php)
- [`PerfbaseBootstrap.php`](/Users/ben/Projects/Perfbase/environment/projects/lib-yii2/src/PerfbaseBootstrap.php)
- lifecycle classes in [`src/Lifecycle`](/Users/ben/Projects/Perfbase/environment/projects/lib-yii2/src/Lifecycle)
- support helpers in [`src/Support`](/Users/ben/Projects/Perfbase/environment/projects/lib-yii2/src/Support)

This package does not implement its own buffering, retry, or persistence layer.

Development
-----------

[](#development)

Verify locally with:

```
composer install
composer run test
composer run phpstan
```

Limitations
-----------

[](#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
-------------

[](#documentation)

Full documentation is available at [perfbase.com/docs](https://perfbase.com/docs).

- **Docs**: [perfbase.com/docs](https://perfbase.com/docs)
- **Issues**: [github.com/perfbaseorg/yii2/issues](https://github.com/perfbaseorg/yii2/issues)
- **Support**:

License
-------

[](#license)

Apache-2.0. See [LICENSE.txt](LICENSE.txt).

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance94

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

4

Last Release

29d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.4 &lt;8.5

v1.0.1PHP &gt;=7.4 &lt;8.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/85d93938cbda24f3ae1b325d2c1ac89e95f1f845365395a693bad51e8b61b5d9?d=identicon)[BenPoulson](/maintainers/BenPoulson)

---

Top Contributors

[![benpoulson](https://avatars.githubusercontent.com/u/1797843?v=4)](https://github.com/benpoulson "benpoulson (10 commits)")

---

Tags

apmphpyii2yii2-frameworkmonitoringprofilingapmyii2Perfbase

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/perfbase-yii2/health.svg)

```
[![Health](https://phpackages.com/badges/perfbase-yii2/health.svg)](https://phpackages.com/packages/perfbase-yii2)
```

###  Alternatives

[bazilio/yii2-newrelic

Newrelic integration for Yii2

23400.1k](/packages/bazilio-yii2-newrelic)[baibaratsky/yii2-rollbar

Rollbar for Yii2

35131.9k](/packages/baibaratsky-yii2-rollbar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
