audunru/memory-usage

记录Laravel中的内存使用情况

v2.0.2 2024-08-25 08:17 UTC

README

Build Status Coverage Status StyleCI

记录HTTP请求期间的内存使用量。峰值内存使用量(以兆字节为单位)将在响应返回前记录。

内存限制可以按请求路径配置。如果您将限制设置为所有请求的25 MiB,您将在日志中看到如下内容:

[2022-01-16 10:49:17] local.WARNING: Maximum memory 50.68 MiB used during request for /api/v1/companies/1/products is greater than limit of 25.00 MiB
[2022-01-16 10:49:29] local.WARNING: Maximum memory 50.39 MiB used during request for /api/v1/companies/1 is greater than limit of 25.00 MiB
[2022-01-16 10:49:29] local.WARNING: Maximum memory 60.04 MiB used during request for /api/v1/companies/1/sales is greater than limit of 25.00 MiB

自v0.3.0起,您还可以记录缓慢的响应。如果您将限制设置为3秒,您将在日志中看到如下内容:

[2022-01-16 10:49:17] local.WARNING: Response time 5.15 s for /api/v1/companies/1/products is greater than limit of 3.00 s

安装

步骤1:使用Composer安装

composer require audunru/memory-usage

配置

通过运行以下命令发布配置文件:

php artisan vendor:publish --tag=memory-usage-config

请打开配置文件,获取有关如何配置日志的进一步说明。

开发

测试

运行测试

composer test