PHPackages                             spiral/profiler - 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. spiral/profiler

ActiveModule

spiral/profiler
===============

Spiral Xhprof Profiler

v3.2.0(2y ago)8105.0k—0%4[4 issues](https://github.com/spiral/profiler/issues)MITPHPPHP &gt;=8.1

Since Nov 25Pushed 2y ago2 watchersCompare

[ Source](https://github.com/spiral/profiler)[ Packagist](https://packagist.org/packages/spiral/profiler)[ RSS](/packages/spiral-profiler/feed)WikiDiscussions 3.0 Synced today

READMEChangelog (10)Dependencies (10)Versions (13)Used By (0)

Spiral Xhprof Profiler
======================

[](#spiral-xhprof-profiler)

[![PHP Version Require](https://camo.githubusercontent.com/21846f12f93caaa3a033b6a340c73d04827f84a373b07e463c700495f8b403a3/68747470733a2f2f706f7365722e707567782e6f72672f73706972616c2f70726f66696c65722f726571756972652f706870)](https://packagist.org/packages/spiral/profiler)[![Latest Stable Version](https://camo.githubusercontent.com/03778b6dde4bb97eb78b46931642f723a53fc8f6839938500bdb52be5712222f/68747470733a2f2f706f7365722e707567782e6f72672f73706972616c2f70726f66696c65722f762f737461626c65)](https://packagist.org/packages/spiral/profiler)[![phpunit](https://github.com/spiral/profiler/actions/workflows/phpunit.yml/badge.svg)](https://github.com/spiral/profiler/actions)[![psalm](https://github.com/spiral/profiler/actions/workflows/psalm.yml/badge.svg)](https://github.com/spiral/profiler/actions)[![Codecov](https://camo.githubusercontent.com/43a33728584ccbafc0ac0f5eef9cfe7f8b4558d72a2f557cc60735c7efc9e76b/68747470733a2f2f636f6465636f762e696f2f67682f73706972616c2f70726f66696c65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/spiral/profiler/)[![Total Downloads](https://camo.githubusercontent.com/a4f3c04c317d1b45ec82bf46c58828fa55a77e0b6b3a0209fe4020de96284d17/68747470733a2f2f706f7365722e707567782e6f72672f73706972616c2f70726f66696c65722f646f776e6c6f616473)](https://packagist.org/packages/spiral/profiler)[![StyleCI](https://camo.githubusercontent.com/08233f169e5ec65f36689cbbf378e78d15e9de9c2340fda3217906423a5a791d/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3434373538313534302f736869656c64)](https://github.styleci.io/repos/447581540)[![](https://camo.githubusercontent.com/4442b73a11753b80fdd7b442ddbfaf8383902c8b9ffa66ed1718e8c62e102f2e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646973636f72642d636861742d6d6167656e74612e737667)](https://discord.gg/8bZsjYhVVk)

Requirements
------------

[](#requirements)

Make sure that your server is configured with following PHP version and extensions:

- PHP 8.1+
- Spiral framework 3.0+

Installation
------------

[](#installation)

To install the package:

```
composer require spiral/profiler
```

After package install you need to add bootloader from the package in your application.

```
use Spiral\RoadRunnerBridge\Bootloader as RoadRunnerBridge;

protected const LOAD = [
    // ...
    Spiral\Profiler\ProfilerBootloader::class,
    // ...
];
```

Define env variables:

```
PROFILER_ENABLE=true
PROFILER_ENDPOINT=http://127.0.0.1:8080/api/profiler/store
PROFILER_APP_NAME="My super app"
PROFILER_MIDDLEWARE_DEFAULT_ENABLED=true
```

Usage
-----

[](#usage)

There are two ways to use profiler:

- Profiler as a middleware
- Profiler as an interceptor

### Profiler as an interceptor

[](#profiler-as-an-interceptor)

Interceptor will be useful if you want to profile some specific part of your application which supports using interceptors.

- Controllers,
- GRPC,
- Queue jobs,
- TCP
- Events.

```
namespace App\Bootloader;

use App\Interceptor\CustomInterceptor;
use Spiral\Bootloader\DomainBootloader;
use Spiral\Core\CoreInterface;

class AppBootloader extends DomainBootloader
{
    protected const SINGLETONS = [
        CoreInterface::class => [self::class, 'domainCore']
    ];

    protected const INTERCEPTORS = [
        \Spiral\Profiler\ProfilerInterceptor::class
    ];
}
```

> Read more about interceptors [here](https://spiral.dev/docs/cookbook-domain-core/3.3/en).

### Profiler as a middleware

[](#profiler-as-a-middleware)

To use profiler as a middleware you need to add it to your router.

#### Global middleware

[](#global-middleware)

```
namespace App\Bootloader;

use Spiral\Bootloader\Http\RoutesBootloader as BaseRoutesBootloader;
use Spiral\Profiler\ProfilerMiddleware;

final class RoutesBootloader extends BaseRoutesBootloader
{
    protected function globalMiddleware(): array
    {
        return [
            ProfilerMiddleware::class,  //  [
                CookiesMiddleware::class,
                SessionMiddleware::class,
                CsrfMiddleware::class,
            ],
            'profiler' => [                  //
