amnuts/timer
Composer 安装命令:
composer require amnuts/timer
包简介
A simple to use timer class
关键字:
README 文档
README
This is a ridiculously simple microsecond timer for you to use within your PHP applications.
It starts the timer when you instantiate the class and from there you can mark points of delta along the way and stop the timer.
Really; could it get simpler?
Usage examples
<?php use Amnuts\Datetime\Timer; $timer = new Timer(); sleep(5); // do something here echo $timer->stop();
and that'll give us the result of:
Started 2020-09-19 16:06:52
Ended 2020-09-19 16:06:57, total time 0d 0h 0m 5.000200s
Simple, but kinda boring. However, if you have a function that you're wanting to time which has lots of parts, then it's useful to place markers throughout and see the difference between each part.
For example:
<?php use Amnuts\Datetime\Timer; $timer = new Timer(); sleep(1); $timer->mark(); sleep(2); $timer->mark(); sleep(3); $timer->stop(); echo $timer;
will give us the result of:
Started 2020-09-19 16:11:59
Δ 0d 0h 0m 1.000200s
Δ 0d 0h 0m 2.000700s
Ended 2020-09-19 16:12:05, total time 0d 0h 0m 6.001800s
The mark method allows us to see the delta between each time it's marked. But it can be even more helpful with supplying a message for the mark:
<?php use Amnuts\Datetime\Timer; $timer = new Timer(); sleep(1); $timer->mark('Starting something slow'); sleep(2); $timer->mark('Ended that and going onto something even slower!'); sleep(3); $timer->stop(); echo $timer;
and that gives us:
Started 2020-09-19 16:14:51
Δ 0d 0h 0m 1.000700s (Starting something slow)
Δ 0d 0h 0m 2.000700s (Ended that and going onto something even slower!)
Ended 2020-09-19 16:14:57, total time 0d 0h 0m 6.001900s
And, to be honest, you don't even need to stop the timer to output the current delta. You could just do this:
<?php
use Amnuts\Datetime\Timer;
$timer = new Timer();
sleep(1);
echo $timer;
sleep(2);
echo $timer;
which produces output such as:
Started 2020-09-19 16:40:47, current delta 0d 0h 0m 1.000100s
Started 2020-09-19 16:40:47, current delta 0d 0h 0m 3.000700s
License
amnuts/timer 适用场景与选型建议
amnuts/timer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「interface」 「gui」 「Opcache」 「opcodes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 amnuts/timer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amnuts/timer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 amnuts/timer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
GUI for PHP's OpCache
GUI to analyze the profiling data collected using XHProf - A Hierarchical Profiler for PHP.
Composer personal web interface. Manage Laravel dependencies without switching to command line!
Laravel 5 - Repositories to the database layer
A Media Manager Built With Vuejs & Laravel
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-20