PHP Classes

File: examples/example_simple2.php

Recommend this page to a friend!
  Packages of Jorge Castro   MultiOne   examples/example_simple2.php   Download  
File: examples/example_simple2.php
Role: Example script
Content type: text/plain
Description: Example script
Class: MultiOne
Execute many tasks in parallel using JavaScript
Author: By
Last change:
Date: 1 year ago
Size: 1,122 bytes
 

 

Contents

Class file image Download
<?php
/** @noinspection PhpUnhandledExceptionInspection */

/** @noinspection PhpUnusedParameterInspection */

use Eftec\MultiOne\MultiOne;
include __DIR__ . '/../vendor/autoload.php';
$work=MultiOne::Factory(
    1000, // miliseconds
    basename(__FILE__), // the file to call (itself)
    4 // number of workers
);
$work->setMethods(
    static function($numWorkers) {
        $work=[
            [["apple","banana","pear","orange","lemon"],5],
            [["alpha","beta","gamma","delta"],4],
            [["tango","charlie","foxtrot"],3],
            [[1,2,3,4,5,6,7,8,9,10,11,12],12],
        ];
        return $work; // we give every worker a work
    },
    static function($idWorker, $payload) {
        usleep(500);
        $txt=str_repeat('?',count($payload[0])).str_repeat('?',$payload[1]-count($payload[0]));
        $current=array_pop($payload[0]);
        if($current===null) {
            return MultiOne::msgAnswer('end',$payload,$txt);
        }
        return MultiOne::msgAnswer('run',$payload,$txt);
    },
    static function($payloads) {
        return 'work done';
    }
);
$work->runAuto();