Control processes in GNU/Linux systems by this package for PHP 8.x
Install it by Composer
> composer require milanowicz/php-thread
Class to control thread for one command
$thread = new Milanowicz\Thread\Threads();
$thread->exec('php scripts/script1.php');
$thread->exec('php scripts/script2.php');
$thread->anyRunning();
$thread->stopAll();
$thread->reset();
Worker to run commands
$worker = new Milanowicz\Thread\Worker([
'command' => '/bin/sleep 2',
'execMaxCounter' => 10, // How many would you execute?
'maxWorkers' => 2, // How process(es) should be started?
'maxExecutionTime' => 120, // Seconds to run php script
'memoryLimit' => '32M', // Maximum for php memory limit
'workerDelayStart' => 1, // Delay for starting processes after each other
'workerRunSleep' => 2, // Sleep to check again if enough processes are running
]);
$worker->setCheckDispatcher(function () { return <bool>; });
$worker->run(); // Main call to start worker loop
$worker->getThread(); // Get current Thread instance
Singleton to control it everywhere you like
$singleton = new Milanowicz\Thread\ThreadSingleton();
$singleton->exec('php scripts/script1.php');
$singleton->exec('php scripts/script2.php');
$singleton->anyRunning();
$singleton->stopAll();
$singleton->reset
Worker and Singleton
$worker = new Milanowicz\Thread\Worker([
'command' => '/bin/sleep 20',
'execMaxCounter' => 10, // How many would you execute?
'maxWorkers' => 2, // How process(es) should be started?
], new Milanowicz\Thread\ThreadSingleton());
$worker->run();
Run all test suites
> composer tests
Run PHP CS Fixer to code styling
> composer style
Run PHPStan to analyze
> composer anlayze
Run PHPUnit tests
> composer test
Run Mutation tests by Infection
> composer infection