oasis / multitasking
Installs: 1 048
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 9
Forks: 0
Open Issues: 3
Requires
- php: >=5.6.1
- ext-pcntl: *
- oasis/event: ^1.0
- oasis/logging: ^1.1
Requires (Dev)
- phpunit/phpunit: ^5.5
README
Multitasking support for PHP, using pcntl library to fork children processes
Installation
oasis/multitasking is an open-source component available at packagist.org
. To require the package, try the following in your project directory:
composer require oasis/multitasking
Background Worker Manager
If you ever want to run something in the background(i.e. a callable
that is often referred to as worker), you should have a look at BackgroundWorkerManager
class. This class provides the following features:
- Run multiple workers in the background (forked process)
- An ordered worker queue which limits the concurrent running worker to a preset number
- Wait functionality for the parent process
Example:
<?php $man = new BackgroundWorkerManager(2); $man->addWorker( function (WorkerInfo $info) { echo sprintf( "This is the #%d worker executed out of a total of %d", $info->currentWorkerIndex, $info->totalWorkers ); }, 10 ); // add 10 workers to the manager $man->run(); // all workers will be executed in order, no more than 2 workes will be running at the same time $man->wait();