zwirek/react-timer-handler 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

zwirek/react-timer-handler

Composer 安装命令:

composer require zwirek/react-timer-handler

包简介

Simple handler for ReactPHP timers

README 文档

README

When react/event-loop timer is set, method will return object of the timer. It is important to hold reference to timer when you want to cancel this timer. But due to the nature of asynchronous live cycle of the process it is likely that reference will be overwritten by the new timer. ReactPHP Timer Handler introduce different approach to handle timers. Each timer has its unique name.

Usage examples

Add timer

$loop = \React\EventLoop\Factory::create();
$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);

$success = $handler->addTimer('example_timer', 1, function (React\EventLoop\Timer\Timer $timer) {
    echo 'example_timer', PHP_EOL;
});

var_dump($success); //prints true

$loop->run();

echo 'done', PHP_EOL;

You can not overwrite your timer accidentally. When run, you will see output from the first timer only.

$loop = \React\EventLoop\Factory::create();
$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);

$first = $handler->addTimer('example_timer', 1, function (React\EventLoop\Timer\Timer $timer) {
    echo 'first', PHP_EOL;
});

$second = $handler->addTimer('example_timer', 1, function (React\EventLoop\Timer\Timer $timer) {
    echo 'second', PHP_EOL;
});

var_dump($first); //prints true
var_dump($second); //prints false

$loop->run();

echo 'done', PHP_EOL;

Timer can be canceled by its name

$loop = \React\EventLoop\Factory::create();
$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);

$timer = $handler->addTimer('example_timer', 1, function (React\EventLoop\Timer\Timer $timer) {
    echo 'example_timer', PHP_EOL;
});

$handler->cancelTimer('example_timer');

$loop->run();

echo 'done', PHP_EOL;

react/event-loop allow to register periodic timer. TimerHandler also allow to register periodic timer by name

$loop = \React\EventLoop\Factory::create();

$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);

$timer = $handler->addPeriodicTimer('periodic_timer', 1, function (React\EventLoop\Timer\Timer $timer) {});

$loop->run();

It is possible to create periodic timer which will be executed limited number of times

$loop = \React\EventLoop\Factory::create();

$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);

$timer = $handler->addLimitedPeriodicTimer('limited_periodic_timer', 1, function (React\EventLoop\Timer\Timer $timer) {}, 5);

$loop->run();

Above timer execute registered handler 5 times at intervals of 1 seconds

To cancel all registered times just simply run:

$handler->cancelAll();

zwirek/react-timer-handler 适用场景与选型建议

zwirek/react-timer-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 177 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「async」 「handler」 「timer」 「react」 「reactphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 zwirek/react-timer-handler 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 177
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-23