PHP code example of multi / processor

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

    

multi / processor example snippets




use processor\MultiJob;

class TestJob extends MultiJob
{
    public function handle()
    {
        echo $this->getData(); // getData获取 每个workId设置的data数据
        sleep(1);
        echo $this->workIndex . PHP_EOL;
        sleep(60);
        echo chr($this->workIndex + 97) . PHP_EOL;
    }
}

$job = new TestJob(100);
$job->init(function ($index){ //每个work进程对应的处理方法
    return "{$index}_abc " . random_int(100, 999) . PHP_EOL;
});
$job->run();