PHP Classes

File: examples/example_simple1.php

Recommend this page to a friend!
  Classes of Jorge Castro   MultiOne   examples/example_simple1.php   Download  
File: examples/example_simple1.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: 3 days ago
Size: 1,004 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"],
            [
"alpha","beta","gamma","delta"],
            [
"tango","charlie","foxtrot"],
            [
1,2,3,4,5,6,7,8,9,10,11,12],
        ];
        return
$work; // we give every worker a work
   
},
    static function(
$idWorker, $payload) {
       
usleep(500);
       
$current=array_pop($payload);
        if(
$current===null) {
            return
MultiOne::msgEnd($payload,$current.' work done');
        }
        return
MultiOne::msgRun($payload,$current);
    },
    static function(
$payloads) {
        return
'work done';
    }
);
$work->runAuto();