PHPackages                             m-derakhshi/laravel-server-timing - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. m-derakhshi/laravel-server-timing

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

m-derakhshi/laravel-server-timing
=================================

Add Server-Timing header information from within your Laravel apps.

097PHP

Since Mar 6Pushed 1y agoCompare

[ Source](https://github.com/m-derakhshi/laravel-server-timing)[ Packagist](https://packagist.org/packages/m-derakhshi/laravel-server-timing)[ RSS](/packages/m-derakhshi-laravel-server-timing/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Server Timings
======================

[](#laravel-server-timings)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a644ed8e07e37a343f7338b3f725e11cfbfeb42a31875839c2b662f527e91b2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6265796f6e64636f64652f6c61726176656c2d7365727665722d74696d696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beyondcode/laravel-server-timing)[![Total Downloads](https://camo.githubusercontent.com/745d6af4aeedb6c6fd0284ddd76131df143932061d2a9cc6b361cd6254256e5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6265796f6e64636f64652f6c61726176656c2d7365727665722d74696d696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beyondcode/laravel-server-timing)

Add Server-Timing header information from within your Laravel apps.

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

[](#installation)

You can install the package via composer:

```
composer require beyondcode/laravel-server-timing
```

Usage
-----

[](#usage)

To add server-timing header information, you need to add the `\BeyondCode\ServerTiming\Middleware\ServerTimingMiddleware::class,` middleware to your HTTP Kernel. In order to get the most accurate results, put the middleware as the first one to load in the middleware stack.

### Laravel 11

[](#laravel-11)

`bootstrap/app.php`

```
return Application::configure(basePath: dirname(__DIR__))
    // ...
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->prepend(\BeyondCode\ServerTiming\Middleware\ServerTimingMiddleware::class);
    })
    // ...
    ->create();
```

### Laravel 10 and below

[](#laravel-10-and-below)

`app/Http/Kernel.php`

```
class Kernel extends HttpKernel
{
    protected $middleware = [
        \BeyondCode\ServerTiming\Middleware\ServerTimingMiddleware::class,
        // ...
    ];
```

---

By default, the middleware measures only three things, to keep it as light-weight as possible:

- Bootstrap (time before the middleware gets called)
- Application time (time to get a response within the app)
- Total (total time before sending out the response)

Once the package is successfully installed, you can see your timing information in the developer tools of your browser. Here's an example from Chrome:

[![CleanShot 2024-03-18 at 13 48 53@2x](https://private-user-images.githubusercontent.com/26432041/313688460-adea40e4-5c34-4aee-9fb7-ad6bac40addc.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU1ODIxOTgsIm5iZiI6MTc3NTU4MTg5OCwicGF0aCI6Ii8yNjQzMjA0MS8zMTM2ODg0NjAtYWRlYTQwZTQtNWMzNC00YWVlLTlmYjctYWQ2YmFjNDBhZGRjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA3VDE3MTEzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNjY2U0YzY5NjdiNDZlMTViYTMwODdlOGJjY2M5OTIwYWQ2NWI1YzY3YTNjNDgxZTYwNzMwYjAxZTEwNjNkNTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.g3M-lc13ybtvJFosFDpuumUrgGPRoX5HOcQKJerzwM0)](https://private-user-images.githubusercontent.com/26432041/313688460-adea40e4-5c34-4aee-9fb7-ad6bac40addc.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU1ODIxOTgsIm5iZiI6MTc3NTU4MTg5OCwicGF0aCI6Ii8yNjQzMjA0MS8zMTM2ODg0NjAtYWRlYTQwZTQtNWMzNC00YWVlLTlmYjctYWQ2YmFjNDBhZGRjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA3VDE3MTEzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNjY2U0YzY5NjdiNDZlMTViYTMwODdlOGJjY2M5OTIwYWQ2NWI1YzY3YTNjNDgxZTYwNzMwYjAxZTEwNjNkNTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.g3M-lc13ybtvJFosFDpuumUrgGPRoX5HOcQKJerzwM0)

Adding additional measurements
------------------------------

[](#adding-additional-measurements)

If you want to provide additional measurements, you can use the start and stop methods. If you do not explicitly stop a measured event, the event will automatically be stopped once the middleware receives your response. This can be useful if you want to measure the time your Blade views take to compile.

```
use BeyondCode\ServerTiming\Facades\ServerTiming;

ServerTiming::start('Running expensive task');

// Take a nap
sleep(5);

ServerTiming::stop('Running expensive task');
```

[![CleanShot 2024-03-18 at 13 51 56@2x](https://private-user-images.githubusercontent.com/26432041/313688611-47e9e692-2bce-4449-a7ea-966fa4701c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sPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA3VDE3MTEzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUwZDhkMjU1MDFiYzQxMmViM2FjYWNkNzBmMzE0NzUzNGI3ZTNiZGJjMzk4YmEzYTg4ZTA4NzVlNTNjOGZkNDcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.vortXioKpgMdmvP9MVe5-LsZRig7dEoZpiDF03HOzA4)

If you already know the exact time that you want to set as the measured time, you can use the `setDuration` method. The duration should be set as milliseconds:

```
ServerTiming::setDuration('Running expensive task', 1200);
```

In addition to providing milliseconds as the duration, you can also pass a callable that will be measured instead:

```
ServerTiming::setDuration('Running expensive task', function() {
    sleep(5);
});
```

Adding textual information
--------------------------

[](#adding-textual-information)

You can also use the Server-Timing middleware to only set textual information without providing a duration.

```
ServerTiming::addMetric('User: '.$user->id);
```

Publishing configuration file
-----------------------------

[](#publishing-configuration-file)

The configuration file could be published using: `php artisan vendor:publish --tag=server-timing-config`

You can disable the middleware by changing the `timing.enabled` configuration to false or adding `SERVER_TIMING_ENABLED=false` to your `.env` file.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Marcel Pociot](https://github.com/mpociot)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor3

3 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/03b3cbbbf98cd8159da3618646e7986b1d5690f8093cd86e1ad0890b9dc6a404?d=identicon)[m-derakhshi](/maintainers/m-derakhshi)

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (13 commits)")[![mechelon](https://avatars.githubusercontent.com/u/26432041?v=4)](https://github.com/mechelon "mechelon (7 commits)")[![binaryk](https://avatars.githubusercontent.com/u/6833714?v=4)](https://github.com/binaryk "binaryk (6 commits)")[![m-derakhshi](https://avatars.githubusercontent.com/u/59544612?v=4)](https://github.com/m-derakhshi "m-derakhshi (3 commits)")[![adamhopkinson](https://avatars.githubusercontent.com/u/1493635?v=4)](https://github.com/adamhopkinson "adamhopkinson (2 commits)")[![mmachatschek](https://avatars.githubusercontent.com/u/10237069?v=4)](https://github.com/mmachatschek "mmachatschek (2 commits)")[![johnwc](https://avatars.githubusercontent.com/u/2798441?v=4)](https://github.com/johnwc "johnwc (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![intellow](https://avatars.githubusercontent.com/u/40676515?v=4)](https://github.com/intellow "intellow (1 commits)")[![hms5232](https://avatars.githubusercontent.com/u/43672033?v=4)](https://github.com/hms5232 "hms5232 (1 commits)")[![wit3](https://avatars.githubusercontent.com/u/5450259?v=4)](https://github.com/wit3 "wit3 (1 commits)")[![drbyte](https://avatars.githubusercontent.com/u/404472?v=4)](https://github.com/drbyte "drbyte (1 commits)")[![sarfraznawaz2005](https://avatars.githubusercontent.com/u/201788?v=4)](https://github.com/sarfraznawaz2005 "sarfraznawaz2005 (1 commits)")[![spekulatius](https://avatars.githubusercontent.com/u/8433587?v=4)](https://github.com/spekulatius "spekulatius (1 commits)")[![sschlein](https://avatars.githubusercontent.com/u/2911113?v=4)](https://github.com/sschlein "sschlein (1 commits)")[![jetwes](https://avatars.githubusercontent.com/u/1346373?v=4)](https://github.com/jetwes "jetwes (1 commits)")

### Embed Badge

![Health badge](/badges/m-derakhshi-laravel-server-timing/health.svg)

```
[![Health](https://phpackages.com/badges/m-derakhshi-laravel-server-timing/health.svg)](https://phpackages.com/packages/m-derakhshi-laravel-server-timing)
```

###  Alternatives

[improved/iterable

Functions to interact with arrays, iterators and other traversable objects

13206.8k3](/packages/improved-iterable)[swiegmann/kirby-menu

This Kirby CMS-Plugin lets you build and render structured menues with a variety of features.

141.4k](/packages/swiegmann-kirby-menu)

PHPackages © 2026

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