drewlabs/laravel-mem-usage
最新稳定版本:v0.1.5
Composer 安装命令:
composer require drewlabs/laravel-mem-usage
包简介
Tracks per request memory usage in a Laravel application
README 文档
README
This library provides a middleware object that allows developpers to query for memory usage of laravel requests. The middleware can be registered globally making it to run on each request or attached to a specific route using middleware aliases.
By default it does nothing with the logged memory information. In order to write it to disk or to application database, developpers must provided event listeners that attached to Drewlabs\Laravel\Memory\Usage\Log class as follow:
// MyMemoryLogListener.php class MyMemoryLogListener { /** * Handle the event. */ public function handle(\Drewlabs\Laravel\Memory\Usage\Log $log): void { // Note: returned value by each of these functions are of type AllocatedMemory{usedMemory, requestedMemory} $alloc1 = $log->getInitialMemoryAllocation(); // memory allocation before handling the request [memory consumed by laravel initialization classed and function ] $alloc2 = $log->getCurrentMemoryAllocation(); // $alloc2 = $alloc1 + memory consume by the actual request handler $diff = $log->getHandlersConsumedMemory(); // Compute the difference $diff = $alloc1 - $alloc 2 // Do something with the logged information } } // Then we bind the event listener to the log event instance in our application service provider // EventServiceProvider.php use Illuminate\Foundation\Support\Providers\EventServiceProvider as BaseServiceProvider; class EventServiceProvider extends BaseServiceProvider { /** * The event listener mappings for the application. * * @var array<class-string, array<int, class-string>> */ protected $listen = [ \Drewlabs\Laravel\Memory\Usage\Log::class => [ \App\Listeners\MyMemoryLogListener::class ], ]; /** * Register application services. * * * @return void */ public function register() { // Call the event service provider instance parent::register(); } }
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-15