定制 drewlabs/laravel-mem-usage 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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();
    }
}

统计信息

  • 总下载量: 79
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固