PHPackages                             fetzi/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. fetzi/server-timing

ActiveLibrary

fetzi/server-timing
===================

server-timing is a package that contains a middlware for adding Server-Timing information to your responses

1.1.0(11mo ago)455.5k↓100%3[1 PRs](https://github.com/fetzi/server-timing/pulls)MITPHPPHP ^8.0CI failing

Since Dec 6Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/fetzi/server-timing)[ Packagist](https://packagist.org/packages/fetzi/server-timing)[ Docs](https://github.com/fetzi/server-timing)[ RSS](/packages/fetzi-server-timing/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (5)Versions (4)Used By (0)

Server-Timing middleware package
================================

[](#server-timing-middleware-package)

[![Packagist](https://camo.githubusercontent.com/8a9209c46993497a7ced6c7efc27c0df8aeb18b86b5a9127803d249faf5f8b0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6665747a692f7365727665722d74696d696e672e737667)](https://packagist.org/packages/fetzi/server-timing)[![Github Actions](https://github.com/fetzi/server-timing/workflows/Build/badge.svg)](https://github.com/fetzi/server-timing/actions)[![StyleCI](https://camo.githubusercontent.com/e63ca080c86011620f2c605890923e44f27eed9f253315ba22df3022c10b305e/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3232363330343739342f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/226304794)[![Maintainability](https://camo.githubusercontent.com/6a5b915adb331ae719eb87e6d94703c579aaffee7cc2b622be4a0c05ee1813e4/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f32633763373063306532643431393632313637632f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/fetzi/server-timing/maintainability)

server-timing is a PHP middleware package that adds the `Server-Timing` header to your responses. This information can be viewed in your web browser, for example in Google Chrome.

More information on the `ServerTiming` response header can be found on [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing).

[![](static/server-timing.png)](static/server-timing.png)

The package automatically adds two default metrics but allows you to add custom metrics as well.

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

[](#installation)

```
composer require fetzi/server-timing

```

Setup
-----

[](#setup)

The package automatically measures two Timing values in the middleware implementation:

1. `Bootstrap`: The time taken in the application bootstrapping phase
2. `Request`: The total time your request handler(s) needed to process your request

To make sure all timings are as exact as possible it is important to add the middleware at the outermost (last) position of your request handler stack.

### PSR-15 Middleware

[](#psr-15-middleware)

To enable the middleware you simply need to add an instance of `Fetzi\ServerTiming\ServerTimingMiddleware` to your middleware stack.

In a [Slim](http://www.slimframework.com/) application you can do this by simply adding

```
$app->add(new ServerTimingMiddleware($container->get(ServerTimings::class)));
```

to your middleware stack code.

### Laravel Middleware

[](#laravel-middleware)

To enable the middleware in your [Laravel](https://laravel.com/) application you need to use the `Fetzi\ServerTiming\Laravel\ServerTimingMiddleware` class.

If you want to enable the middleware in general simply add the class definition to the `$middleware` array in the `Kernel` class. If you want to enable the middleware only if a condition is met, you need to override the `handle` method of the `Kernel` as demonstrated [here](https://paste.laravel.io/KkeVq).

Usage
-----

[](#usage)

To be able to add your custom server timings you need to make sure that you register the `ServerTimings` class as a singleton in your dependency injection container. This allows you to inject the `ServerTimings` class into any other class and create and measure a custom server timing.

```
function fetchUsers()
{
    $fetchUsers = $this->serverTimings->create('fetchUsers');
    $fetchUsers->start();
    $users = $this->db->getUsers();
    $fetchUsers->stop();

    return $users;
}
```

This code will generate a new server timing named `fetchUsers` and by calling the `start` and the `stop` method the the execution time is measured.

### Creating a ServerTiming instance

[](#creating-a-servertiming-instance)

The `ServerTimings` class provides a `create` method to create a `ServerTiming` instance that is automatically registered and will be sent back by the middleware.

```
// create a ServerTiming with a name
$serverTiming = $serverTimings->create('foo');

// create a ServerTiming with a name and a description
$serverTiming = $serverTimings->create('foo', 'bar');
```

### Measuring a ServerTiming

[](#measuring-a-servertiming)

The `ServerTiming` instance provides two methods for starting and stopping the measurement.

```
// normal usage
$serverTiming->start();
// ...
$serverTiming->stop();

// set a manual start value (a microtime value as float)
$serverTiming->start(1000000.00);
// ...
$serverTiming->stop();
```

The middleware will make sure to collect all measured ServerTiming instances and append their values in the `Server-Timing` response header.

License
-------

[](#license)

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

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance50

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~1944 days

Total

2

Last Release

355d ago

PHP version history (2 changes)1.0.0PHP ^7.2

1.1.0PHP ^8.0

### Community

Maintainers

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

---

Top Contributors

[![fetzi](https://avatars.githubusercontent.com/u/3509426?v=4)](https://github.com/fetzi "fetzi (7 commits)")[![wimpichjo](https://avatars.githubusercontent.com/u/203976988?v=4)](https://github.com/wimpichjo "wimpichjo (1 commits)")

---

Tags

laravelmiddlewarephpphp7psr-15psr-7server-timing

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/fetzi-server-timing/health.svg)

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

###  Alternatives

[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169175.3k2](/packages/spatie-laravel-mix-preload)[rareloop/lumberjack-core

A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code

42153.1k18](/packages/rareloop-lumberjack-core)

PHPackages © 2026

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