PHPackages                             internetrix/silverstripe-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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. internetrix/silverstripe-server-timing

ActiveSilverstripe-vendormodule[Logging &amp; Monitoring](/categories/logging)

internetrix/silverstripe-server-timing
======================================

Add server-timing information to headers

1.0(5y ago)72741[1 issues](https://github.com/Internetrix/silverstripe-server-timing/issues)BSD-3-ClausePHP

Since Aug 24Pushed 5y ago6 watchersCompare

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

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

Introduction
------------

[](#introduction)

This module allows developers to add Server-Timing information to headers for a SilverStripe application.

The [Server Timing API](https://w3c.github.io/server-timing/) allows you to pass request-specific timing data from the server to the browser via response headers.

This is an example of the Server Timing header information looks in development tools of Chrome:

[![Example](docs/Example.PNG)](docs/Example.PNG)

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

[](#requirements)

- SilverStripe Framework ^4.0

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

[](#installation)

```
composer require internetrix/silverstripe-server-timing

```

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

[](#configuration)

It is recommended to add the `\Internetrix\Control\Middleware\ServerTimingMiddleware::class` to the top of the middleware execution pipeline. This will require the middleware to be added before the SilverStripe CMS has been fully bootstrapped.

To do so we can edit the SilverStripe CMS entry point file located either at `public/index.php`, or directly in your project root at `index.php` if your project doesn't use the public web root.

Find the line that instantiates `HTTPApplication`. Call the `addMiddleware` method on the `HTTPApplication` instance and pass it an instance of the `ServerTimingMiddleware` class. Remember to pass it an instance of `ServerTiming`:

```
$app = new HTTPApplication($kernel);

// Add the following line to configure our ServerTimingMiddleware
$app->addMiddleware(new ServerTimingMiddleware(ServerTiming::inst()));

$app->addMiddleware(new ErrorControlChainMiddleware($app));
$response = $app->handle($request);
$response->output();

```

By default the following metrics is added to the response headers:

- **Bootstrap:** Time until it takes for the `ServerTimingMiddleware` to be called
- **Application:** Time it takes to receive a response from the SilverStripe application.
- **Total:** The total duration being a request being sent to server until right before a response being sent back to the client-side.

Adding more timing metrics
--------------------------

[](#adding-more-timing-metrics)

A developer can also add more timing-metrics to the header by using `start` and `end` methods on the `Internetrix\Helper\ServerTiming` class. Please note that the name of the metric should be passed as the parameter and needs to be the same for `start` and `stop`.

The `start` and `stop` methods can be called from within different parts of the SilverStripe application.

```
ServerTiming::start('Custom Metric to Measure');
// do something in the code
ServerTiming::end('Custom Metric to Measure');

```

Alternatively, we can also use the `addMetric` method on `ServerTiming` when we want to measure a metric from the start of the request. The duration for the metric will then be calculated using the start time of the request and the current time.

```
// add a metric that measure the time between the start of the request and now
ServerTiming::addMetric('Metric to Add');

```

Client-Side Analytics Integration
---------------------------------

[](#client-side-analytics-integration)

**Note**: The interface may only available in secure contexts (HTTPS) in some browsers.

The default and custom timing metrics defined in the Server-Timing headers can be retrieved on the client-side for third-party Analytics integration (i.e Google Analytics) using the PerformanceObserver Web API using JavaScript.

Add the following script to the base `Page.ss` template file and/or any pages before the `` tag you want the server-timing API information to be retrieved on the client-side. The script will push all server-timing metrics data to a global `dataLayer` JavaScript variable which can then be used for analytics.

```

    try {
            window.dataLayer = window.dataLayer || [];
            serverTimings = {};
            // Create the performance observer.
            const po = new PerformanceObserver((list) => {
                for (const entry of list.getEntries()) {
                    // Logs each server timing data for this response to object
                    if ('serverTiming' in entry) {
                        entry.serverTiming.forEach(function (timing) {
                            let name = timing.name;
                            serverTimings[name] = timing.duration;
                        });
                    }
                }
            });
            // Start listening for `navigation` entries to be dispatched.
            po.observe({type: 'navigation', buffered: true});
            // Push all the server timing object to the datalayer as a new event
            dataLayer.push({
                'event' : 'ServerTimings',
                'timings' : [serverTimings]
            });
        } catch (e) {
            // Do nothing if API is not support by browser
        }

```

This is an example of how the default Server-Timing metrics are stored within the global `dataLayer` variable:

[![DataLayer-Example](docs/datalayer.PNG)](docs/datalayer.PNG)

Credits
-------

[](#credits)

This module was inspired and based on the following package for the Laravel framework:

.

It has been refactored to be compatible with the SilverStripe framework.

Licence
-------

[](#licence)

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

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Total

2

Last Release

2138d ago

Major Versions

0.1 → 1.02020-08-24

### Community

Maintainers

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

![](https://avatars.githubusercontent.com/u/38059212?v=4)[Jon Su](/maintainers/jkersu)[@jkersu](https://github.com/jkersu)

---

Top Contributors

[![jkersu](https://avatars.githubusercontent.com/u/38059212?v=4)](https://github.com/jkersu "jkersu (1 commits)")

---

Tags

silverstripeMetricstimingserver timingstiming metricstiming events

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[silverstripe/framework

The SilverStripe framework

7313.7M2.8k](/packages/silverstripe-framework)[silverstripe/cms

The SilverStripe Content Management System

5253.6M1.4k](/packages/silverstripe-cms)[silverstripe/admin

SilverStripe admin interface

262.8M382](/packages/silverstripe-admin)[lekoala/silverstripe-cms-actions

Add actions to your models in SilverStripe

39344.8k30](/packages/lekoala-silverstripe-cms-actions)[phptek/sentry

Sentry.io integration for SilverStripe. Binds Sentry.io to SilverStripe's error &amp; exception handling subsystem.

16210.6k4](/packages/phptek-sentry)[lekoala/silverstripe-softdelete

Soft delete extension for SilverStripe

11236.3k](/packages/lekoala-silverstripe-softdelete)

PHPackages © 2026

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