PHP code example of yarcode / yii2-daemon

1. Go to this page and download the library: Download yarcode/yii2-daemon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yarcode / yii2-daemon example snippets



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);
                }
            }
        });
    }
}