nsommer89 / php-exec-measure
PHP操作的耗时测量库。
v1.0.2
2023-02-20 20:25 UTC
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-15 23:32:49 UTC
README
关于
PHP操作的耗时测量库。
要求
最低 php8.0
使用Composer安装
composer require nsommer89/php-exec-measure
.. 或者GitHub页面: https://github.com/nsommer89/php-exec-measure
库使用
基本使用示例
<?php
require_once __DIR__ . '/path/to/autoload.php';
$measurement = new \Nsommer89\PhpExecMeasure\SimpleMeasurement();
($measurement)->fn(function () {
// .. the code you want to measure time consumption
});
foreach ($measurement->getResult()->toArray() as $key => $value) {
echo $key . ': ' . $value . PHP_EOL;
}
示例结果
milliseconds: 26.175975799560547
microseconds: 26175.975799560547
seconds: 0.026175975799560547
start: 1676922692.509042
end: 1676922692.535218
start_unixtime: 1676922692
end_unixtime: 1676922692
其他格式
JSON
...
$resultJson = $measurement->getResult()->toJson();
...
获取值
...
$result = $measurement->getResult();
$seconds = $result->seconds();
$milliseconds = $result->milliseconds();
$microseconds = $result->microseconds();
...
命令行使用
测量PHP文件执行时间
$ ./vendor/bin/php-exec-measure -f <filename>.php
以JSON格式输出
$ ./vendor/bin/php-exec-measure -f <filename>.php --json
JSON结果
{"milliseconds":26.175975799560547,"microseconds":26175.975799560547,"seconds":0.026175975799560547,"start":1676922692.509042,"end":1676922692.535218,"start_unixtime":1676922692,"end_unixtime":1676922692}
忽略错误
$ ./vendor/bin/php-exec-measure -f <filename>.php --json --ignore-errors
将输出记录到文件
$ ./vendor/bin/php-exec-measure -f <filename>.php -o
指定日志输出文件名
$ ./vendor/bin/php-exec-measure -f <filename>.php --output <log file name>.log
-f <file path>
是唯一必需的参数<filename>.php
将始终相对于项目路径
由 nsommer89 用 ♡ 制作