PHPackages                             petrknap/php-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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. petrknap/php-profiler

Abandoned → [petrknap/profiler](/?search=petrknap%2Fprofiler)Library[Debugging &amp; Profiling](/categories/debugging)

petrknap/php-profiler
=====================

PHP profiler for short-term &amp; long-term profiling

v2.2.0(1y ago)797.2k↓44.2%[2 PRs](https://github.com/petrknap/php-profiler/pulls)2LGPL-3.0-or-laterPHPPHP &gt;=8.1

Since Dec 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/petrknap/php-profiler)[ Packagist](https://packagist.org/packages/petrknap/php-profiler)[ Docs](https://github.com/petrknap/php-profiler)[ Fund](https://petrknap.github.io/donate.html)[ RSS](/packages/petrknap-php-profiler/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (21)Used By (2)

PHP profiler for short-term &amp; long-term profiling
=====================================================

[](#php-profiler-for-short-term--long-term-profiling)

This tool allows you to monitor performance and detect memory leaks as well as inconsistent performance behavior of your application over time.

Basic profiling
---------------

[](#basic-profiling)

For basic profiling you can use a profiling helper. The [`Profiling`](./src/Profiling.php) will allow you to profile between `start` and `finish` methods calls.

```
namespace PetrKnap\Profiler;

$profiling = Profiling::start();
// do something
$profile = $profiling->finish();

printf('It took %.1f s to do something.', $profile->getDuration());
```

The [`Profiling`](./src/Profiling.php) is simple and **cannot be turned on and off** easily. So a [profiler](./src/ProfilerInterface.php) was created for the purpose of hard-coded more complex profiling.

Complex profiling
-----------------

[](#complex-profiling)

Request a [profiler](./src/ProfilerInterface.php) as a dependency and call a `profile` method on it.

```
namespace PetrKnap\Profiler;

function doSomething(ProfilerInterface $profiler): string {
    return $profiler->profile(function (): string {
        return 'something';
    })->process(fn (ProfileInterface $profile) => printf(
        'It took %.1f s to do something.',
        $profile->getDuration(),
    ));
}
```

### How to enable / disable it

[](#how-to-enable--disable-it)

It can be easily enabled, or disabled **through the DI**, which provides either the [`Profiler`](./src/Profiler.php) or the [`NullProfiler`](./src/NullProfiler.php).

```
namespace PetrKnap\Profiler;

echo doSomething(new Profiler());
echo doSomething(new NullProfiler());
```

Useful features
---------------

[](#useful-features)

### Take snapshot

[](#take-snapshot)

If you need to **measure the current values**, just call the `takeSnapshot` method on the [`Profiling`](./src/Profiling.php), or a [profiler](./src/ProfilerInterface.php).

```
namespace PetrKnap\Profiler;

$profiling = Profiling::start();
// do something
$profiling->takeSnapshot();
// do something more
$profile = $profiling->finish();

printf('There are %d memory usage records.', count($profile->getMemoryUsages()));
```

If you want to automate it then [take snapshot on tick](#take-snapshot-on-tick). Or you can use a more practical [cascade profiling](#cascade-profiling).

#### Take snapshot on tick

[](#take-snapshot-on-tick)

For greater precision, you can take **snapshot on each `N` tick**.

```
declare(ticks=2); // this declaration is important (N=2)

namespace PetrKnap\Profiler;

$profiling = Profiling::start(takeSnapshotOnTick: true);
(fn () => 'something')();
$profile = $profiling->finish();

printf('There are %d memory usage records.', count($profile->getMemoryUsages()));
```

This will result in **very detailed code tracking**, which can degrade the performance of the monitored application.

### Cascade profiling

[](#cascade-profiling)

The `profile` method provides you a nested [profiler](./src/ProfilerInterface.php) that you can use for more detailed cascade profiling.

```
namespace PetrKnap\Profiler;

$profile = (new Profiler())->profile(function (ProfilerInterface $profiler): void {
    // do something
    $profiler->profile(function (): void {
        // do something more
    });
});

printf('There are %d memory usage records.', count($profile->getMemoryUsages()));
```

---

Run `composer require petrknap/profiler` to install it. You can [support this project via donation](https://petrknap.github.io/donate.html). The project is licensed under [the terms of the `LGPL-3.0-or-later`](./COPYING.LESSER).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 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 ~293 days

Recently: every ~675 days

Total

12

Last Release

576d ago

Major Versions

v0.2.0.0 → v1.0.02016-09-16

v1.3.0 → v2.0.02024-10-11

PHP version history (4 changes)v0.0.0.1PHP &gt;=5.3

v0.2.0.0PHP &gt;=5.4

v1.3.0PHP &gt;=5.5

v2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/c0e19f2ea17567eb9f536d1e00595b83630dfb8b2df6e7e422e06a9a48e85585?d=identicon)[petrknap](/maintainers/petrknap)

---

Top Contributors

[![petrknap](https://avatars.githubusercontent.com/u/8299754?v=4)](https://github.com/petrknap "petrknap (30 commits)")

---

Tags

debugdebuggingperformance-analysisperformance-monitoringphpphp-libraryprofileprofilerprofilingdebugprofilerdebuggingprofilingprofileperformance-monitoringperformance-analysis

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/petrknap-php-profiler/health.svg)

```
[![Health](https://phpackages.com/badges/petrknap-php-profiler/health.svg)](https://phpackages.com/packages/petrknap-php-profiler)
```

###  Alternatives

[barryvdh/laravel-debugbar

PHP Debugbar integration for Laravel

19.2k124.3M624](/packages/barryvdh-laravel-debugbar)[php-debugbar/php-debugbar

Debug bar in the browser for php application

4.4k21.3M40](/packages/php-debugbar-php-debugbar)[fruitcake/laravel-debugbar

PHP Debugbar integration for Laravel

19.1k662.9k29](/packages/fruitcake-laravel-debugbar)[tracy/tracy

😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.

1.8k24.4M1.3k](/packages/tracy-tracy)[fruitcake/laravel-telescope-toolbar

Toolbar for Laravel Telescope based on Symfony Web Profiler

8041.6M3](/packages/fruitcake-laravel-telescope-toolbar)[laracraft-tech/laravel-xhprof

Easy XHProf setup to profile your laravel application!

235321.4k](/packages/laracraft-tech-laravel-xhprof)

PHPackages © 2026

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