Download the PHP package n-hor/pcntl-parallel without Composer
On this page you can find all versions of the php package n-hor/pcntl-parallel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download n-hor/pcntl-parallel
More information about n-hor/pcntl-parallel
Files in n-hor/pcntl-parallel
Package pcntl-parallel
Short Description Execute PHP code in parallel with single or persistent task worker.
License MIT
Informations about the package pcntl-parallel
Simple solution for running PHP code concurrently
This package for running code in parallel and creating a pool of processes to execute various tasks (like queue workers).
Improve performance of your php app with this package!
Installation
Requirements
- PHP >= 8.1
- ext-sockets
- ext-pcntl https://www.php.net/manual/en/intro.pcntl.php
- posix (optional)
Usage
SingleTaskWorker
Usage of SingleTaskWorker
:
If an exception occurs in a parallel process, Worker returns WorkerExceptionMessage
as output.
Example With timeout exception:
You could use wrapper of SingleTaskWorker
for running multiple single workers:
You can wait for only a specific task to complete:
Example of running with concurrency limitation:
PersistenceWorker
is a worker that is started once and runs in the background as a daemon.
It receives and executes tasks from the parent process.
Usage of PersistenceWorker
:
PersistenceWorkersPool
PersistenceWorkersPool
A pool of processes for sending tasks.
A free worker will be selected to perform the task.
If all workers are busy, it will wait until at least one is free.
You can specify a maximum wait time, in which case an exception will be thrown.
Usage of PersistenceWorkersPool
:
Testing
Credits
License
The MIT License (MIT). Please see License File for more information.
PHP sandbox:
All versions of pcntl-parallel with dependencies
ext-pcntl Version *
ext-sockets Version *