PHP Classes

File: examples/examplecli_simple1.php

Recommend this page to a friend!
  Classes of Jorge Castro   MultiOne   examples/examplecli_simple1.php   Download  
File: examples/examplecli_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: 2 days ago
Size: 937 bytes
 

Contents

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

/** @noinspection PhpUnusedParameterInspection */

use Eftec\MultiOne\MultiOne;

include
__DIR__ . '/../vendor/autoload.php';
MultiOne::Factory(
   
1000, // every miliseconds
   
basename(__FILE__), // the url to call
)->setMethods(
    static function(
$numWorkers, $payload): array { // the initial call
       
$_SESSION['USERNAME'] = 'admin';
        return [
"Start",
];
    },
    static function(
$idWorker, $payload): array { // the worker call
        // it reads the data and reduces to 1.
       
$username=$_SESSION['USERNAME']??null;
        if(
$username===null) {
            throw new
RuntimeException('no user is not set');
        }
        return
MultiOne::msgRun("$username:{$payload['line']}","@$username> ");
    }
)
    ->
setCli('> ','100%','600px') // we use a cli
   
->runAuto();