{"id":13828056,"url":"https://github.com/beyondcode/laravel-server-timing","last_synced_at":"2025-05-14T05:10:25.036Z","repository":{"id":40452712,"uuid":"237911234","full_name":"beyondcode/laravel-server-timing","owner":"beyondcode","description":"Add Server-Timing header information from within your Laravel apps.","archived":false,"fork":false,"pushed_at":"2025-04-04T13:24:38.000Z","size":42,"stargazers_count":562,"open_issues_count":3,"forks_count":44,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-11T11:13:44.577Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beyondcode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-02-03T07:45:37.000Z","updated_at":"2025-05-04T19:14:39.000Z","dependencies_parsed_at":"2024-01-18T05:11:40.164Z","dependency_job_id":"8ac04ae3-1064-4434-8a9f-60fb3b52fe52","html_url":"https://github.com/beyondcode/laravel-server-timing","commit_stats":{"total_commits":19,"total_committers":10,"mean_commits":1.9,"dds":0.6842105263157895,"last_synced_commit":"9b25380c9f0e0b67594849a260b7d9cb6b9a9767"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-server-timing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-server-timing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-server-timing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-server-timing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beyondcode","download_url":"https://codeload.github.com/beyondcode/laravel-server-timing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253554120,"owners_count":21926615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T09:02:30.339Z","updated_at":"2025-05-14T05:10:25.010Z","avatar_url":"https://github.com/beyondcode.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Laravel Server Timings\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-server-timing.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-server-timing)\n[![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-server-timing.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-server-timing)\n\nAdd Server-Timing header information from within your Laravel apps.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require beyondcode/laravel-server-timing\n```\n\n## Usage\n\nTo add server-timing header information, you need to add the `\\BeyondCode\\ServerTiming\\Middleware\\ServerTimingMiddleware::class,` middleware to your HTTP Kernel.\nIn order to get the most accurate results, put the middleware as the first one to load in the middleware stack.\n\n### Laravel 11\n`bootstrap/app.php`\n```php\nreturn Application::configure(basePath: dirname(__DIR__))\n    // ...\n    -\u003ewithMiddleware(function (Middleware $middleware) {\n        $middleware-\u003eprepend(\\BeyondCode\\ServerTiming\\Middleware\\ServerTimingMiddleware::class);\n    })\n    // ...\n    -\u003ecreate();\n```\n\n### Laravel 10 and below\n`app/Http/Kernel.php`\n```php\nclass Kernel extends HttpKernel\n{\n    protected $middleware = [\n        \\BeyondCode\\ServerTiming\\Middleware\\ServerTimingMiddleware::class,\n        // ...\n    ];\n```\n\n---\n\nBy default, the middleware measures only three things, to keep it as light-weight as possible:\n\n- Bootstrap (time before the middleware gets called)\n- Application time (time to get a response within the app)\n- Total (total time before sending out the response)\n\nOnce the package is successfully installed, you can see your timing information in the developer tools of your browser. Here's an example from Chrome:\n\n![CleanShot 2024-03-18 at 13 48 53@2x](https://github.com/beyondcode/laravel-server-timing/assets/26432041/adea40e4-5c34-4aee-9fb7-ad6bac40addc)\n\n## Adding additional measurements\n\nIf 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.\n\n```php\nuse BeyondCode\\ServerTiming\\Facades\\ServerTiming;\n\nServerTiming::start('Running expensive task');\n\n// Take a nap\nsleep(5);\n\nServerTiming::stop('Running expensive task');\n```\n\n![CleanShot 2024-03-18 at 13 51 56@2x](https://github.com/beyondcode/laravel-server-timing/assets/26432041/47e9e692-2bce-4449-a7ea-966fa4701cdb)\n\n\nIf 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:\n\n```php\nServerTiming::setDuration('Running expensive task', 1200);\n```\n\nIn addition to providing milliseconds as the duration, you can also pass a callable that will be measured instead:\n\n\n```php\nServerTiming::setDuration('Running expensive task', function() {\n    sleep(5);\n});\n```\n\n## Adding textual information\n\nYou can also use the Server-Timing middleware to only set textual information without providing a duration.\n\n```php\nServerTiming::addMetric('User: '.$user-\u003eid);\n```\n\n## Publishing configuration file\n\nThe configuration file could be published using:\n`php artisan vendor:publish --tag=server-timing-config`\n\nYou can disable the middleware by changing the `timing.enabled` configuration to false or adding `SERVER_TIMING_ENABLED=false` to your `.env` file.\n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email marcel@beyondco.de instead of using the issue tracker.\n\n## Credits\n\n- [Marcel Pociot](https://github.com/mpociot)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondcode%2Flaravel-server-timing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeyondcode%2Flaravel-server-timing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondcode%2Flaravel-server-timing/lists"}