beyondcode/laravel-server-timing
Composer 安装命令:
composer require beyondcode/laravel-server-timing
包简介
Add Server-Timing header information from within your Laravel apps.
README 文档
README
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.
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
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:
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');
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.
ServerTiming::addMetric('User: '.$user->id);
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
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 marcel@beyondco.de instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
beyondcode/laravel-server-timing 适用场景与选型建议
beyondcode/laravel-server-timing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.2M 次下载、GitHub Stars 达 571, 最近一次更新时间为 2020 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「beyondcode」 「laravel-server-timing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 beyondcode/laravel-server-timing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 beyondcode/laravel-server-timing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 beyondcode/laravel-server-timing 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add Server-Timing header information from within your Laravel apps.
Add Server-Timing header information from within your Laravel apps.
Perform various self diagnosis tests on your Laravel application.
Add Server-Timing header information from within your Laravel apps.
Marcel Pociot's based beyondcode/laravel-visual-diff adapted for Laravel 7
A PHP SDK for building Claude Code hooks.
统计信息
- 总下载量: 2.2M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 573
- 点击次数: 31
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-03