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

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

phpner/laravel-profiler
=======================

Laravel package for measuring and logging memory usage and execution time

v0.1.1(9mo ago)028MITPHPPHP &gt;=8.1

Since Aug 10Pushed 9mo agoCompare

[ Source](https://github.com/phpner/laravel-profiler)[ Packagist](https://packagist.org/packages/phpner/laravel-profiler)[ RSS](/packages/phpner-laravel-profiler/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Laravel Memory Profiler
=======================

[](#laravel-memory-profiler)

> Measure **peak memory** and **execution time** in your Laravel app — for HTTP requests and Artisan commands. Ships with headers, logs, and optional Telescope integration.

[![Packagist](https://camo.githubusercontent.com/20289ddfaabb21e7c5be1c71492fa0db24d66bebd18f17a4372b76554091c34b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e65722f6c61726176656c2d70726f66696c65722e737667)](https://packagist.org/packages/phpner/laravel-profiler)[![PHP](https://camo.githubusercontent.com/05985a778602681eeb1f19de6bb4df3ca37ecf8e91ea6d6e6ff94951e3c280c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e65722f6c61726176656c2d70726f66696c6572)](https://www.php.net/)[![Laravel](https://camo.githubusercontent.com/67180151902ea0188f8db83059a9bd58307c02e50f863470748938b3455ddbef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825453225383025393331322e782d726564)](https://camo.githubusercontent.com/67180151902ea0188f8db83059a9bd58307c02e50f863470748938b3455ddbef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825453225383025393331322e782d726564)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)

---

Features
--------

[](#features)

- 🔎 **Precise metrics**: duration (ms), start/end/peak memory and memory diff.
- 🌐 **HTTP profiling** via middleware + optional response headers: `X-Memory-Peak`, `X-Duration-ms`.
- 🧰 **Artisan profiling** via a simple trait wrapper.
- 🧱 **Manual spans** (start/stop) via the service or facade.
- 🪵 **Pluggable outputs**: app log, Laravel Telescope (or both).
- 🎚️ **Threshold**: only log when peak memory exceeds N bytes.

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

[](#requirements)

- PHP **&gt;= 8.1**
- Laravel **10.x / 11.x / 12.x**

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

[](#installation)

```
composer require phpner/laravel-profiler
php artisan vendor:publish --tag=config --provider="Phpner\\MemoryProfiler\\MemoryProfilerServiceProvider"
```

This publishes `config/laravel-memory-profiler.php`.

Quick start
-----------

[](#quick-start)

### HTTP requests

[](#http-requests)

Register the middleware (global or route group):

```
// app/Http/Kernel.php
protected $middleware = [
    // ...
    \Phpner\MemoryProfiler\Middleware\HttpProfiler::class,
];
```

When enabled, each request will:

- write a log entry with metrics and request context;
- (optionally) add headers `X-Memory-Peak` and `X-Duration-ms` to the response.

### Artisan commands

[](#artisan-commands)

Wrap your command logic with the provided trait:

```
use Illuminate\Console\Command;
use Phpner\MemoryProfiler\Console\Concerns\ProfilesMemory;

class ImportUsers extends Command
{
    use ProfilesMemory;

    protected $signature = 'users:import';

    public function handle(): int
    {
        return $this->withMemoryProfiling(function () {
            // your command logic
            $this->info('Importing...');
            // ...
            return 0; // exit code
        });
    }
}
```

The profiler will log command name and exit code along with metrics.

### Manual spans

[](#manual-spans)

Use the service (DI) or the facade to measure any piece of code.

```
use Phpner\MemoryProfiler\MemoryProfiler; // service
use Phpner\MemoryProfiler\Facades\MemoryProfiler as MP; // facade

// 1) Service
public function show(MemoryProfiler $profiler)
{
    $ctx = $profiler->start('code');
    // ... your code ...
    $profiler->stop($ctx, [
        'label' => 'users.show',
        'meta'  => ['id' => 42],
    ]);
}

// 2) Facade
$ctx = MP::start('code');
// expensive work
MP::stop($ctx, ['label' => 'expensive.segment']);
```

Configuration
-------------

[](#configuration)

`config/laravel-memory-profiler.php`:

```
return [
    'enabled'          => env('MEMORY_PROFILER_ENABLED', true),
    'driver'           => env('MEMORY_PROFILER_DRIVER', 'log'), // log | telescope | both
    'threshold'        => env('MEMORY_PROFILER_THRESHOLD', 0),  // bytes; 0 = log everything
    'response_headers' => env('MEMORY_PROFILER_HEADERS', true),
];
```

**Common .env options**

```
MEMORY_PROFILER_ENABLED=true
MEMORY_PROFILER_DRIVER=both     # log | telescope | both
MEMORY_PROFILER_THRESHOLD=0     # e.g. 2097152 (2 MB)
MEMORY_PROFILER_HEADERS=true
```

Output
------

[](#output)

### Response headers (HTTP)

[](#response-headers-http)

```
X-Memory-Peak: 1048576
X-Duration-ms: 123

```

### Log entry (example)

[](#log-entry-example)

```
{
  "duration_ms": 123,
  "memory_start": 524288,
  "memory_end": 786432,
  "memory_peak": 1048576,
  "memory_diff": 262144,
  "type": "http",          // or "artisan" / "code"
  "label": "users.show",   // when provided for manual spans
  "method": "GET",
  "path": "api/users/42",
  "route": "users.show",
  "status": 200
}
```

### Telescope (optional)

[](#telescope-optional)

Set `MEMORY_PROFILER_DRIVER=telescope` or `both`. Entries appear in Telescope **Log** section with the `memory` tag.

Why this package?
-----------------

[](#why-this-package)

- Lightweight and framework-native.
- Zero vendor lock‑in: works with logs you already collect; Telescope is optional.
- Transparent: you decide where to profile (global, group, specific commands, or manual spans).

Tips
----

[](#tips)

- Start with `threshold=0` in dev to see everything; raise it in prod to reduce noise.
- Put the middleware only on routes you care about if you want a narrower focus.
- Pair with request IDs/correlation IDs in your logger to join app logs and memory profiles.

Roadmap
-------

[](#roadmap)

- Queue job middleware.
- Blade/Laravel Debugbar-like panel.
- Per-route configuration overrides.

Contributing
------------

[](#contributing)

PRs and issues are welcome! Please include tests where it makes sense.

License
-------

[](#license)

Released under the **MIT** License.

---

[![telescope](images/telescope.gif)](images/telescope.gif)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance57

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

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

Unknown

Total

1

Last Release

281d ago

### Community

Maintainers

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

---

Tags

laravel-profiling-memory-performance-php-telescope

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpner-laravel-profiler/health.svg)

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

###  Alternatives

[barryvdh/laravel-debugbar

PHP Debugbar integration for Laravel

19.1k124.3M624](/packages/barryvdh-laravel-debugbar)[fruitcake/laravel-debugbar

PHP Debugbar integration for Laravel

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

A beautiful error page for Laravel applications.

566146.7M471](/packages/spatie-laravel-ignition)[spatie/laravel-ray

Easily debug Laravel apps

31538.4M2.8k](/packages/spatie-laravel-ray)[laradumps/laradumps

LaraDumps is a friendly app designed to boost your Laravel PHP coding and debugging experience.

1.3k1.3M29](/packages/laradumps-laradumps)[glhd/laravel-dumper

382801.4k](/packages/glhd-laravel-dumper)

PHPackages © 2026

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