reply/microtime
Composer 安装命令:
composer require reply/microtime
包简介
Microtime library
README 文档
README
Microtime is a library written in pure PHP that provides an interface and a class to work with microseconds. PHP offers the possibility to get the current timestamp in seconds and microseconds via the microtime() function, but the resulting two values must always be converted so that the number of microseconds since the unix epoch is obtained. The Microtime class does this work for you. This allows you to create a Microtime object from different formats and convert it into different formats like DateTime object, integer and string.
Requirements
Microtime requires the following:
- PHP 7.1 or higher
Installation
Microtime is installed via Composer. To add a dependency to Microtime in your project, either
Run the following to use the latest stable version
composer require reply/microtime
or if you want the latest master version
composer require reply/microtime:dev-master
You can of course also manually edit your composer.json file
{
"require": {
"reply/microtime": "^2.0"
}
}
Getting started
The following is a basic usage example of the Microtime library:
<?php use Reply\Microtime\Microtime; // Creates a Microtime object from current timestamp $microtime = Microtime::fromNow(); // Creates a Microtime object from a string containing seconds and microseconds $microtime = Microtime::fromString('0.34497500 1589445224'); // or $microtime = Microtime::fromMicrotime('0.34497500 1589445224'); // Creates a new Microtime object from an integer containing the microseconds since the unix epoch $microtime = Microtime::fromInt(1589445224344975); // or $microtime = Microtime::fromMicroseconds(1589445224344975); // Creates a new Microtime object from a float containing the result of the microtime(true) function $microtime = Microtime::fromFloat(1589445622.7431); // Creates a new Microtime object from an integer containing the seconds since the unix epoch $microtime = Microtime::fromSeconds(1589445622); // Creates a new Microtime object from a DateTime object $microtime = Microtime::fromDateTime(new \DateTime()); // Returns the microtime as string $string = $microtime->toString(); // or $string = (string) $microtime; // or $string = "Time in microseconds: $microtime"; // Returns the microtime as integer $int = $microtime->toInt(); // Returns the microtime as float $float = $microtime->toFloat(); // Returns the microtime as string in the format of the microtime() function $string = $microtime->toMicrotime(); // Returns the microtime in a DateTime object $dateTime = $microtime->toDateTime(); // Returns the microtime in a DateTimeImmutable object $dateTimeImmutable = $microtime->toDateTimeImmutable();
Contributing
You're welcome to contribute to Microtime. Below are some of the things that you can do to contribute.
- Fork the repository and request a pull to the develop branch.
- Submit bug reports or feature requests to GitHub.
reply/microtime 适用场景与选型建议
reply/microtime 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.67k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 reply/microtime 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 reply/microtime 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 25.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-25