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

Overview

Laravel Server Timings

Latest Version on Packagist Build Status Quality Score Total Downloads

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

Installation

You can install the package via composer:

composer require beyondcode/laravel-server-timing

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.

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:

image

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.

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

// do something

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

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

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

Publishing configuration file

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

You can disable the middleware changing the timing.enabled configuration to false.

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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Tag v1.2.0 doesn't contain all changes (PHP 8)

    Tag v1.2.0 doesn't contain all changes (PHP 8)

    It seems like there was an issue with the last release (which should contain PHP 8 support) because the merged PRs are not in that tag.

    https://github.com/beyondcode/laravel-server-timing/compare/1.1.0...1.2.0 https://github.com/beyondcode/laravel-server-timing/compare/1.1.0...master

    https://github.com/beyondcode/laravel-server-timing/issues/19#issuecomment-748042390

    opened by mmachatschek 6
  • [Feature]

    [Feature] "enable" config flag

    Hey, first of all: Nice package!

    It would be cool to enable and disable the middleware via a new config flag, just in case you want to disable the middleware.

    opened by fragkp 1
  • Add Image to README to show how to access the information

    Add Image to README to show how to access the information

    I had to dig through Twitter to find how to see the information this package sends to the browser. It would be great if this image were in the README.

    image

    I will send a PR to add the image.

    opened by intellow 0
  • composer error

    composer error

    Problem 1 - Root composer.json requires beyondcode/laravel-server-timing ^1.3 -> satisfiable by beyondcode/laravel-server-timing[1.3.0]. - beyondcode/laravel-server-timing 1.3.0 requires illuminate/support 5.8.*|^6.0|^7.0|^8.0 -> found illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.

    You can also try re-running composer require with an explicit version constraint, e.g. "composer require beyondcode/laravel-server-timing:*" to figure out if any version is installable, or "composer require beyondcode/laravel-server-timing:^2.1" if you know which you need.

    what this ?

    opened by mderakhshi 0
  • Add php doc comments for ServerTiming facade

    Add php doc comments for ServerTiming facade

    Add php doc comments for each public function for the facade, so that there is help text along with IDE intellisense to know about that static functions it supports.

    Feel free to modify the description of the static functions if they seem incorrect.

    opened by johnwc 0
  • Added an `addMessage` utility method, with a test and docs update

    Added an `addMessage` utility method, with a test and docs update

    I went a bit deep trying to find out how to add a message (ie an entry without a duration) to the server timing output - as it turns out, there is an example in the docs but it has somehow been pushed a section down into the 'Publishing configuration file' setting.

    By that point, I'd forked the repo and created an addMessage utility.

    opened by adamhopkinson 1
Releases(1.3.0)
Owner
Beyond Code
Beyond Code
A simple way to add 301/302 redirects within CraftCMS.

Redirector plugin for Craft CMS 3.x A simple way to add 301/302 redirects within CraftCMS. This is the first CraftCMS plugin written by myself so plea

Jae Toole 1 Nov 25, 2021
🕵🏻‍♂️  The easiest way to respect the "do not track" header in Laravel

trackable The easiest way to respect the "do not track" header in Laravel Installation composer require s360digital/trackable API Trackable will expos

s360 2 Oct 7, 2022
PHP Simple Response, XML, JSON,... auto response with accept in request's header

simple-response Simple package to handle response properly in your API. This package does not include any dependency. Install Via Composer $ composer

Phuong Danh 3 Dec 8, 2021
Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items.

Filament Quick Create Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items from any page. Installation Instal

Adam Weston 45 Dec 27, 2022
Use Nanoids within your laravel application.

Laravel Nanoid Introduction A simple drop-in solution for providing nanoid support for the IDs of your Eloquent models. (Stripe-like IDs) Installing c

Malico 8 May 17, 2022
Manage meta data based on URL path within your app.

Laravel SEO Manager This package provides simple functionality to manage SEO tags based on URL path within your Laravel application. You can put the U

Michael Rubel 20 Oct 20, 2022
A Laravel Wrapper for the CoinDCX API. Now easily connect and consume the CoinDCX Public API in your Laravel apps without any hassle.

This package provides a Laravel Wrapper for the CoinDCX API and allows you to easily communicate with it. Important Note This package is in early deve

Moinuddin S. Khaja 2 Feb 16, 2022
Enhance your laravel apps with WhatsApp's Cloud API

Enhance your laravel apps with WhatsApp's Cloud API Use Whatsapp API in your Laravel app! Support us Investing on this package is defintely a good mov

Ricardo Sawir 10 Dec 1, 2022
Live Helper Chat - live support for your website. Featuring web and mobile apps, Voice & Video & ScreenShare. Supports Telegram, Twilio (whatsapp), Facebook messenger including building a bot.

Live helper chat It's an open-source powered application, which brings simplicity and usability in one place. With live helper chat you can bring live

Live Helper Chat 1.7k Dec 29, 2022
Textpattern-jquery-ui-theme - The jQuery UI theme used within the Textpattern CMS admin-side.

Textpattern jQuery UI theme The jQuery UI theme used within the Textpattern CMS admin-side. Supported web browsers Chrome, Edge, Firefox, Safari and O

Textpattern CMS 12 Jan 10, 2022
How to get cookies from users' browser and send the information to your email address and telegram bot

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

MAXWELL 3 Dec 3, 2022
Ignition: a beautiful error page for Laravel apps

Ignition is a beautiful and customizable error page for Laravel applications running on Laravel 5.5 and newer. It is the default error page for all Laravel 6 applications.

Spatie 260 Dec 29, 2022
Manage self-hosted Google Fonts in Laravel apps

This package makes self-hosting Google Fonts as frictionless as possible for Laravel users. To load fonts in your application, register a Google Fonts embed URL and load it with the @googlefonts Blade directive.

Spatie 386 Dec 19, 2022
Automatically disable Google's FLoC in Laravel apps

Automatically disable Google's FLoC in Laravel apps This package will automatically disable Google's FLoC. Support us We invest a lot of resources int

Spatie 68 Oct 21, 2022
A Docker container for Laravel web apps

Ubuntu Docker container for Laravel web applications Docker-laravel is a LEMP image for running Laravel web applications. It extends docker-base, whic

Mark Macdonald 121 Nov 18, 2022
A collection of classes to be extended/used in laravel apps for quick development

laraquick A collection of classes to be extended/used in laravel applications for quick development. Introduction The library contains traits with wel

Ezra Obiwale 35 Dec 13, 2022
Postier is a Laravel API automation platform to transfer data and to sync apps.

Postier is a Laravel API automation platform to transfer data and to sync apps. You can build workflows with data and actions of multiple apps and apply logics to the data!

null 55 Oct 28, 2022
Laravel Breadcrumbs - An easy way to add breadcrumbs to your @Laravel app.

Introduction Breadcrumbs display a list of links indicating the position of the current page in the whole site hierarchy. For example, breadcrumbs lik

Alexandr Chernyaev 269 Dec 21, 2022
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.

Webdevetc BlogEtc - Complete Laravel Blog Package Quickly add a blog with admin panel to your existing Laravel project. It has everything included (ro

WebDevEtc. 227 Dec 25, 2022