tasque/event-loop
最新稳定版本:v0.1.5
Composer 安装命令:
composer create-project tasque/event-loop
包简介
README 文档
README
Run a ReactPHP event loop within a conventional PHP application using Tasque.
Why?
To allow periodic background tasks, such as sending keep-alive or heartbeat messages, to be performed in a traditional PHP environment where there would otherwise be no event loop.
Usage
Install this package with Composer:
$ composer install tasque/event-loop
Configure Nytris platform:
nytris.config.php
<?php declare(strict_types=1); use Nytris\Boot\BootConfig; use Nytris\Boot\PlatformConfig; use Tasque\EventLoop\TasqueEventLoopPackage; use Tasque\TasquePackage; $bootConfig = new BootConfig(new PlatformConfig(__DIR__ . '/var/cache/nytris/')); $bootConfig->installPackage(new TasquePackage()); $bootConfig->installPackage(new TasqueEventLoopPackage()); return $bootConfig;
Setting a timer
Just use a standard ReactPHP timer, as long as the package is configured in nytris.config.php as above.
index.php
<?php declare(strict_types=1); use React\EventLoop\Loop; require_once __DIR__ . '/vendor/autoload.php'; Loop::addPeriodicTimer(1, function () { print 'Timer elapsed' . PHP_EOL; });
Awaiting a ReactPHP promise from a thread
<?php declare(strict_types=1); use Tasque\EventLoop\TasqueEventLoop; /* * This will cause the current thread (which may be the main thread * as well as a background thread) to pause until the promise is resolved, * in which case the result will be returned, or rejected, in which case * the reason will be thrown. */ $result = TasqueEventLoop::await($promise);
See also
统计信息
- 总下载量: 5.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-30