phpgt/async
Composer 安装命令:
composer require phpgt/async
包简介
Promise-based non-blocking operations.
README 文档
README
To be able to run asynchronous code in PHP, a loop needs to run in the background to observe and dispatch events, and handle the resolution of promises.
This repository provides the concepts of a Loop, different Timer implementations and a publish-subscribe model for Event objects.
Example usage
A loop with three individual timers at 1 second, 5 seconds and 10 seconds.
$timeAtScriptStart = microtime(true); $timer = new IndividualTimer(); $timer->addTriggerTime($timeAtScriptStart + 1); $timer->addTriggerTime($timeAtScriptStart + 5); $timer->addTriggerTime($timeAtScriptStart + 10); $timer->addCallback(function() use($timeAtScriptStart) { $now = microtime(true); $secondsPassed = round($now - $timeAtScriptStart); echo "Number of seconds passed: $secondsPassed", PHP_EOL; }); $loop = new Loop(); $loop->addTimer($timer); echo "Starting...", PHP_EOL; $loop->run();
Proudly sponsored by
统计信息
- 总下载量: 3.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-12