disfasia/php-timing
Composer 安装命令:
composer require disfasia/php-timing
包简介
Get execution times of a full script or parts of it
README 文档
README
A simple static class to dissect execution times of a full script or parts of it.
Getting Started
Include Timing.php via include, require or composer autoload and use it as a static class.
Methods
Timing:: start('name') / stop('name')
Calculate the execution time between two points.
Timing::start('random calc');
for ($i = 0; $i < 10000; $i++) {
$r = rand();
}
Timing::stop('random calc');
Timing:: break
Saves the time elapsed since the script started to the break point
$var = rand();
sleep(2);
Timing::break();
$var = rand();
Timing:: measure('name', callback)
Calculate the execution time of a function
$returnVal = 0;
for ($i = 1; $i < 3; $i++) {
$returnVal += Timing::measure('someFunction('.$i.')', function() use ($i) {
sleep($i);
return $i;
});
}
var_dump($returnVal);
Timing:: addCallback( callback )
Adds a function called every time a new timing has been saved
Timing::addCallback(function($key, $time) {
var_dump("Collected timing for: $key: ". round($time,4));
});
Timing:: getTimings($round = 3, $slowThreshold = -INF, callable $cb )
Returns all saved times under a key=>value array
Array
(
[start] => 0
[random calc] => 0.0003
[someFunction(1)] => 1.0001
[break @ sample.php:45] => 1.0006
[someFunction(2)] => 2.0001
)
disfasia/php-timing 适用场景与选型建议
disfasia/php-timing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 294 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 disfasia/php-timing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 disfasia/php-timing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 294
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-03-23