PHPackages                             eftec/multione - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. eftec/multione

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

eftec/multione
==============

A multi process library using PHP

1.3(1y ago)140MITPHP

Since Dec 27Pushed 1y ago2 watchersCompare

[ Source](https://github.com/EFTEC/MultiOne)[ Packagist](https://packagist.org/packages/eftec/multione)[ Docs](https://github.com/EFTEC/MultiOne)[ RSS](/packages/eftec-multione/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

MultiOne
========

[](#multione)

MultiOne is a library to execute concurrent tasks programmed in PHP using JavaScript.

This library is focused to run local task easily and without much extra boilerplate.

The goal is to be able to run CPU intensive tasks using multiples cores by distributing every task in different workers (what does the job). It also adds a new functionality, it allows to simulate a Command Line Interface (CLI) using the web.

[![Packagist](https://camo.githubusercontent.com/5d19f2831084bf5cb60d07699dc5680f4bfc304b49e90b70d2a50b89d0705c3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65667465632f4d756c74694f6e652e737667)](https://packagist.org/packages/eftec/MultiOne)[![Total Downloads](https://camo.githubusercontent.com/bfbf10ee8b48380901e0c13d20a614ba396f2cc308951d4d29436d7efc95cf71/68747470733a2f2f706f7365722e707567782e6f72672f65667465632f4d756c74694f6e652f646f776e6c6f616473)](https://packagist.org/packages/eftec/MultiOne)![Maintenance](https://camo.githubusercontent.com/0c8f829897840ac35cb3daf181a719612c0f64c0ed5fca3c7b90ed7591169162/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032352e737667)![composer](https://camo.githubusercontent.com/7a6cce75e3353cd615b111f2f4ff50dec30cf814dddb88b2613f656cec298330/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d706f7365722d253345322e302d626c75652e737667)![php](https://camo.githubusercontent.com/59558613d05bebac3748d4f75f0c94435dec5fb11d059b448c2d172e25d82120/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e342d677265656e2e737667)![php](https://camo.githubusercontent.com/5cd91a78fb469ca20b235b6951fb6dd77bda78ac4633eb432e93699bcb141589/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e342d677265656e2e737667)

[![docs/img5.png](docs/img5.png)](docs/img5.png)

- [MultiOne](#multione)
    - [How to use it?](#how-to-use-it)
    - [Logic](#logic)
    - [How to synchronize and share information between every worker?](#how-to-synchronize-and-share-information-between-every-worker)
    - [Command Line Interface (CLI)](#command-line-interface-cli)
        - [Example](#example)
    - [Example of multi operations](#example-of-multi-operations)
    - [Changelog](#changelog)

How to use it?
--------------

[](#how-to-use-it)

Install this library using Composer

```
composer require eftec/multione

```

And call it as follows:

```
use Eftec\MultiOne\MultiOne;
include __DIR__ . '/../vendor/autoload.php';
$multiOne = MultiOne::Factory(
    1000, // every miliseconds
    basename(__FILE__), // the url to call
    4 // the number of workers
)->setMethod(
    static function($numWorkers):array { // the initial call
        // todo code
        $result=[];
        for($instance=0; $instance'end','result'=>'done','ui'=>'done'];
        }
        return ['result'=>'working', 'ui'=>"Worker: $idWorker"];
    },
    static function($bodies) { // the worker-end call
        echo "all workers ended";
    }
)->setHtmls(
    '%s', // how the content is draw
    '', // how every worker is draw
    '', // how the worker-end is draw.
    "loading ⏳" // the loading ui. If empty, then it don't use loading ui
)->runAuto();
```

The browser will show the next screen [![docs/img1.png](docs/img1.png)](docs/img1.png)

> In the folder examples you can find examples of code.

Logic
-----

[](#logic)

There are 3 functions (defined by **setMethod**) that are called in different stages of the process

```
setMethod(
    static function($numWorkers):array {
      // the initial call (returns an array with all the payload for each worker)
    },
    static function($idWorker, $body):array {
      // the worker call
    },
    static function($bodies) {
      // the worker-end call, it returns a message.
    }
```

- The initial function is called at the beginner of the operation.
    - It must create the initial payload, it also display the UI and it could show some visual content.
    - After the initial function is called, then JavaScript (in the HTML) does the rest of operation and coordination.
- Every "n" milliseconds, every worker is called (unless it is in use). Each worker receives the load of its worker.
    - Once the worker is done, it must return the next structure:
        - **type** the type of result, example: "end" or "run".
            - If a worker returns end, the the worker will stop its operation.
            - If none is set then it uses "run".
        - **result** the result (load) of the worker. If none is set, then it uses the **ui** (if any) or empty
        - **ui** the visual result of the worker. If none is set, then it uses **result**
- When all workers are finished, then worker\_end is executed.
    - It receives the load of all workers and it results a visual text.

[![docs/img2.png](docs/img2.png)](docs/img2.png)

How to synchronize and share information between every worker?
--------------------------------------------------------------

[](#how-to-synchronize-and-share-information-between-every-worker)

You can use the payload to synchronize the operations of every worker.

[![docs/img3.png](docs/img3.png)](docs/img3.png)

However, if it is not enough, then you can use the next alternatives:

- You can use an external library such as eftec/cacheone, to share information between workers
- You can use APCU, Redis, Memcache, database or file system
- The library contains 3 methods to save file locally
    - **MultiOne::getGetData** to get some data using a local file
    - **MultiOne::getSetData** to set some data using a local file
    - **MultiOne::getSetDataSafe** to get some data, replace the value, and save in a safe way

[![docs/img4.png](docs/img4.png)](docs/img4.png)

Command Line Interface (CLI)
----------------------------

[](#command-line-interface-cli)

It is possible to run the library to display a command line interface on web.

[![docs/imgcli.png](docs/imgcli.png)](docs/imgcli.png)

In CLI mode, the code calls a single worker only when the user inputs a value in the input text.

### Example

[](#example)

```
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"], // the initial screen
];
    },
    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();
```

Where:

```
MultiOne::msgAnswer('run','text to add to the console','a prompt'); // run,full,error
```

> The text to display could contains colors. Example:

```
MultiOne::msgAnswer('run','red textyellow background');
```

Example of multi operations
---------------------------

[](#example-of-multi-operations)

You can find this example in the example folder

Lets say we need to execute 100 operations in 4 workers

First, we create the 4 workers

```
MultiOne::Factory(
    1000, // every miliseconds
    basename(__FILE__), // the url to call
    4     // the number of workers
)
```

Then, we create the initial load and we split in 4 workers

```
static function($numWorkers):array { // the initial call
    $result=[];
    $numOper=100;
    $split=ceil($numOper/$numWorkers);
    for($instance=0; $instance$split*$instance,'task'=>[
          'init'=>($split*$instance)+$split,
          'end'=>$split*$instance]
          ];
    }
    return $result;
}
```

Then, every worker must do the job

```
static function($idWorker, $body):array { // the worker call
    $body['done'] += 1;
    if($body['done']>=$body['task']['end']) {
        $body['done']='ok';
        return MultiOne::msgAnswer('end',$body,'done');
    }
    usleep(random_int(500, 1500));
    MultiOne::msgAnswer('run',$body,"Worker: $idWorker");
}
```

// And when all jobs are done, we could close it. It could be used to merge all the results. It only needs to return a visual result.

```
static function($body) { // the worker-end call
    echo "all workers ended";
}
```

Optionally we could do changes in the UI.

Finally, our code could look as follows:

```
MultiOne::Factory(
    1000, // every miliseconds
    basename(__FILE__), // the url to call
    4     // the number of workers
)->setMethods(
    static function($numWorkers):array { // the initial call
        $result=[];
        $numOper=100;
        $split=ceil($numOper/$numWorkers);
        for($instance=0; $instance$split*$instance,'task'=>[
            'init'=>($split*$instance)+$split,
            'end'=>$split*$instance]
            ];
        }
        return $result;
    },
    static function($idWorker,$body):array { // the worker call
        $body['done'] += 1;
        if($body['done']>=$body['task']['end']) {
            $body['done']='ok';
            return MultiOne::msgAnswer('end',$body,'done');
        }
        usleep(random_int(500, 1500));

        return MultiOne::msgAnswer('run',$body,"#$idWorker {$body['done']}");
    },
    static function($body) { // the worker-end call
        echo "all worker ended";
    }
)->runAuto();
```

Changelog
---------

[](#changelog)

- 1.3 2025-01-04
    - Added CLI
    - Added sessions. By default it uses sessions.
- 1.2 2025-01-02
    - Fixed a problem with PHP 8.4
- 1.1 2024-12-27
    - fixed a small bug in initialize some arguments
    - fixed a bug with some examples.
- 1.0 2024-12-27
    - first version

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance40

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

4

Last Release

499d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bf6ba9d7f6f6c3ecde2779a29e1a4948f0f338c074ddceb3fbeb79c6dd1e68c?d=identicon)[JorgeCastro](/maintainers/JorgeCastro)

---

Top Contributors

[![jorgecc-business-account](https://avatars.githubusercontent.com/u/12418702?v=4)](https://github.com/jorgecc-business-account "jorgecc-business-account (5 commits)")[![jorgecc](https://avatars.githubusercontent.com/u/9570242?v=4)](https://github.com/jorgecc "jorgecc (1 commits)")

---

Tags

phpmultiprocess

### Embed Badge

![Health badge](/badges/eftec-multione/health.svg)

```
[![Health](https://phpackages.com/badges/eftec-multione/health.svg)](https://phpackages.com/packages/eftec-multione)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
