centraldesktop / parallel
Easily allows forking up to a max number of processes
Installs: 20 957
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 12
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.6
- ext-pcntl: *
- ext-posix: *
- psr/log: ~1.0
Requires (Dev)
- monolog/monolog: >=1.4.1
- pdepend/pdepend: 1.1.0
- phpmd/phpmd: 1.4.*
- phpunit/phpunit: >=3.7.0
- squizlabs/php_codesniffer: 1.4.5
This package is not auto-updated.
Last update: 2024-10-26 13:51:57 UTC
README
An easy to use and simple library for doing parallel processing using simple process forks.
All credit should go to the amazing maintainers of Perl's (CPAN) Parallel::ForkManager which I used for about 10 years.
To use:
Add this package to your composer dependencies.
use CentralDesktop\Parallel\ForkManager;
// build an object, limit to total concurrent processes.
You must declare(ticks = 1); in order for signal handing to work properly in PHP
$fm = new ForkManager(10); $fm->start();
while ($fm->alive()) { if ($fm->start()) { continue; }
do_something();
$fm->stop(); } $fm->shutdown_all();
You probably may want to handle specific signals by installing signal handlers.
$fm->set_parent_sighandler(array($this, 'parent_signal_handler'));
$fm->set_child_sighandler(array($this, 'child_signal_handler'));