yarcode / yii2-daemon
Yii2 daemon based on ReactPHP
Installs: 5 817
Dependents: 2
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- react/react: ^0.4.2
- yiisoft/yii2: ~2
This package is not auto-updated.
Last update: 2024-11-09 20:50:39 UTC
README
Yii2 daemon based on ReactPHP
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yarcode/yii2-daemon
or add
"yarcode/yii2-daemon": "*"
Usage
Extend the YarCode\Yii2\Daemon\DaemonCommand
class and add your own prepare()
implementation.
<?php
namespace console\controllers;
use YarCode\Yii2\Daemon\DaemonCommand;
class AsyncController extends DaemonCommand
{
public function prepare()
{
$this->loop->addPeriodicTimer(1, function() {
\Yii::$app->db->createCommand('SELECT 1')->execute();
});
$this->loop->addPeriodicTimer(0.1, function() {
while ($task = \Yii::$app->async->receiveTask('search')) {
if ($task->execute()) {
\Yii::$app->async->acknowledgeTask($task);
}
}
});
}
}