wgqi1126/swoole-worker

Swoole job worker helper

0.1.0 2023-05-23 10:29 UTC

This package is auto-updated.

Last update: 2024-04-23 12:40:03 UTC


README

Swoole 协程并发执行器

用法

<?php

use Wgqi1126\SwooleWorker\SwooleJob;
use Swoole\Coroutine\Channel;
use Wgqi1126\SwooleWorker\SwooleWorker;

require_once __DIR__ . '/vendor/autoload.php';

$job = new class implements SwooleJob {
    public function master(Channel $channel)
    {
        print "master\n";
        for ($i = 0; $i < 100; $i++) $channel->push($i);
    }

    public function worker($data = null)
    {
        print "worker-{$data}\n";
        sleep(1);
    }
};
$worker = new SwooleWorker($job);
$worker->run();