PHP code example of workerman / redis-queue

1. Go to this page and download the library: Download workerman/redis-queue 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/ */

    

workerman / redis-queue example snippets



Workerman\Worker;
use Workerman\Lib\Timer;
use Workerman\RedisQueue\Client;

$worker = new Worker();
$worker->onWorkerStart = function () {
    $client = new Client('redis://127.0.0.1:6379');

    $client->subscribe('user-1', function($data) {
        echo "user-1\n";
        var_export($data);
    });

    $client->subscribe('user-2', function($data) {
        echo "user-2\n";
        var_export($data);
    });

    $client->onConsumeFailure(function (\Throwable $exception, $package) {
        echo "consume failure\n";
        echo $exception->getMessage(), "\n";
        var_export($package);
    });

    Timer::add(1, function() use ($client) {
        $client->send('user-1', ['some', 'data']);
    });
};

Worker::runAll();