Download the PHP package yidas/worker-dispatcher without Composer
On this page you can find all versions of the php package yidas/worker-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yidas/worker-dispatcher
More information about yidas/worker-dispatcher
Files in yidas/worker-dispatcher
Package worker-dispatcher
Short Description PHP multi-processing task dispatcher with managing workers
License MIT
Homepage https://github.com/yidas/php-worker-dispatcher
Informations about the package worker-dispatcher
PHP Worker Dispatcher
PHP multi-processing task dispatcher with managing workers
Features
-
Multi-Processing implementation on native PHP-CLI
-
Tasks Dispatching to each worker process
- Elegant Interface for setup and use
OUTLINE
- Demonstration
- Introduction
- Requirements
- Installation
- Usage
- Option
- callbacks.process
- callbacks.task
- Option
DEMONSTRATION
Use multi-processing to dispatch tasks with generating workers based on CPU cores:
Use multi-processing to digest jobs from queue:
INTRODUCTION
This library is implemented by PHP PCNTL control, which provides a main PHP-CLI to fork multiple child processes to share tasks, and even can use for high concurrency application with infinite loop setting.
Since PHP has no shared variables or queue mechanism natively, if you don’t have an external job queue, this library provides a task average dispatcher to simply solve the core distributed processing problem.
REQUIREMENTS
This library requires the following:
- PHP PCNTL
- PHP CLI 5.4.0+
INSTALLATION
Run Composer in your project:
composer require yidas/worker-dispatcher ~1.0.0
Then you could use the class after Composer is loaded on your PHP project:
USAGE
Calling the run()
method statically with options as argument, WorkerDispatcher will start to dispatch tasks (if any), and then fork the number of workers according to the environment or settings, and wait for all forked processes to complete or terminate the main process.
The setting example with all options is as following:
Options
Option | Type | Deafult | Description |
---|---|---|---|
debug | boolean | false | Debug mode |
workers | integer | (auto) | The number of workers(processes) to fork. (The default is the same as the number of CPU cores) |
config | multitype | null | The custom variable used to bring in the callback function |
tasks | multitype | array | For dispatching to each forked process. - Array: Each value of array will be dispatched to all forked processes. - Integer: The number of loops dispatched to all forked processes. - false: Perform finite loop. |
callbacks.process | callable | nul | Callback function called after each forked process is created |
callbacks.task | callable | nul | Callback function called in each task loop of each forked process |
callbacks.process
Callback function called after each forked process is created
Argument | Type | Deafult | Description |
---|---|---|---|
$config | multitype | null | The custom variable used to bring in the callback function |
$workerId | integer | (auto) | The sequence number of the worker(processes) in current function (Start from 1) |
$tasks | multitype | array | Tasks array list for the worker(processes) in current function |
callbacks.task
Callback function called in each task loop of each forked process
Argument | Type | Deafult | Description |
---|---|---|---|
$config | multitype | null | The custom variable used to bring in the callback function |
$workerId | integer | (auto) | The sequence number of the worker(processes) in current function (Start from 1) |
$tasks | multitype | array | The value of each tasks array list for each worker(processes) in current function |