pe / component-process
Process management based on ext-pcntl and ext-posix
Installs: 1 538
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.0
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: ~6.0
Suggests
- ext-pcntl: *
- ext-posix: *
- ext-proctitle: *
This package is auto-updated.
Last update: 2024-10-11 19:16:54 UTC
README
The following versions of PHP are supported.
- PHP 7.0+
Installation
To install, use composer:
php composer.phar require pe/component-process
Usage
Simple manager usage:
<?php namespace PE\Component\Process; // Instantiate manager $manager = new Manager(); // Create process $process = new Process(function (Process $process) { //TODO do some stuff... }); // Execute process $manager->fork($process); $manager->fork($process); $manager->fork($process); $manager->fork($process);// <-- this will be ignored because we set max executed processes // Wait until processes completed $manager->wait();
Demonize any long executed code:
<?php namespace PE\Component\Process; use Psr\Log\NullLogger; // Define path to pid file, must be writable by php user $pidPath = sys_get_temp_dir() . '/daemon.pid'; // Instantiate a daemon $daemon = new Daemon(function () { //TODO do some stuff... }, $pidPath); // Instantiate logger $logger = new NullLogger(); // Start execution in background $daemon->start($logger); // You can check if daemon is still running by call: $daemon->isRunning(); // You can break execution by call: $daemon->stop($logger);