承接 lexide/chronos 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

lexide/chronos

Composer 安装命令:

composer require lexide/chronos

包简介

Provides classes that return timestamps

README 文档

README

Chronos provides classes that return timestamps in order to abstract dependencies on system time. Mostly this is useful when unit testing code, as you are able to mock the TimeProviderInterface and not rely on calls to get system time

It also has a stopwatch, which uses the time providers to generate durations in seconds

Installation

composer require lexide/chronos

To use the lexide/syringe DI config supplied with this library, add the following to your composer.json

"extra": {
    "lexide/puzzle-di": {
        "whitelist": {
            "lexide/syringe": [
                "lexide/chronos"
            ]
        }
    }
}

NOTE: you will need to install lexide/puzzle-di in your project to take advantage of this feature

TimeProviders

The TimeProviders included in this library all return the number of seconds from a given point-in-time. Each class has a get method which is used to get the current time. When mocking these classes, you can set an expectation on this method to return values that simulate a period of time having elapsed.

There are a number of Provider classes supplied in this library:

  • TimeProvider - returns a unix timestamp in seconds
  • MilliTimeProvider- returns a unix timestamp with millisecond precision
  • MicroTimeProvider- returns a unix timestamp with microsecond precision
  • NanoTimeProvider returns an arbitrary timestamp with nanosecond precision

NOTE: The NanoTimeProvider does not return a unix timestamp. It is based on the hrtime function which returns nanoseconds elapsed from an arbitrary point-in-time, such as system start time. As this point-in-time cannot be known beforehand, NanoTimeProvider cannot be used for date calculations, only for timing durations

Custom TimeProviders

If you need to use a different unit of time, such as an integer of milliseconds, you can create a new class that implements Lexide\Chronos\TimeProvider\TimeProviderInterface. In its get method, you can return any integer or float value that meets your requirements.

TimeSkippers

TimeSkippers delay PHP from processing a script, using sleep() and related functions. Each class has a skip method which requires an argument representing the number of seconds to delay by. Note that this value is always the number of seconds; passing 100 to the MicroTimeSkipper will delay by 100 seconds, not 100 microseconds

The Skipper classes available in this library are:

  • TimeSkipper - delay's processing by whole second increments
  • MilliTimeProvider- delay's processing by millisecond increments
  • MicroTimeProvider- delay's processing by microsecond increments
  • NanoTimeProvider delay's processing by nanosecond increments

Stopwatches

The StopWatch classes perform the common function of timing the duration of a task. They use TimeProviders to capture a starting point-in-time and work out the difference between the start and a second point-in-time, when requested

StopWatch class

To use a StopWatch, you must call start() on it to capture the starting time. Then you can call stop() to stop timing and return the time difference. Alternatively, if you want to continue timing, a call to duration() will return the time elapsed but keep the watch running, allowing duration() to be called multiple times.

MultiStopWatch

The MultiStopWatch is useful in situations where you want to record several concurrent durations without having a StopWatch for each one. The functionality is the same as for StopWatch but in each case, a key argument is used to separate concurrent timings.

For example, calling start("foo") and then start("bar") will start two timers. If you then call stop("foo") the timer for "bar" will continue to run until stop is called with that key

StopWatch modes

Both StopWatches can operate in continuous or interval modes, which affect the value returned from calls to duration()

In continuous mode, duration() will return the difference between the current time and the initial start time, so measuring the total time since the timer was started.

Interval mode differs by setting the start time to the current time for each call to duration(). This allows measurement of the intervals between duration() calls; equivalent to individual lap times when using a real stopwatch

lexide/chronos 适用场景与选型建议

lexide/chronos 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.02k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 lexide/chronos 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lexide/chronos 我们能提供哪些服务?
定制开发 / 二次开发

基于 lexide/chronos 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-05