A Library to handle a multiple Symfony process component, by creating a command which can be handled in asynchronous (threads).
- PHP 7.2
- PHP 8.0
$ composer require fghazaleh/multi-thread-manager
$threadSize = 10;
$threadManager = \FGhazaleh\MultiThreadManager\ThreadManager::create($threadSize);
or
$threadSize = 10;
$threadStartDelay = 1; //milliseconds
$pollInterval = 120; //milliseconds
$threadManager = new \FGhazaleh\MultiThreadManager\ThreadManager(
new \FGhazaleh\MultiThreadManager\ThreadSettings(
$threadSize, $threadStartDelay, $pollInterval
)
);
or
$threadSettings = \FGhazaleh\MultiThreadManager\ThreadSettings::createFromDefault();
$threadManager = new \FGhazaleh\MultiThreadManager\ThreadManager(
$threadSettings
);
Add shell script command thread.
$threadManager->addThread('php -r "echo 123; exit(0);"');
Add Symfony process thread.
$process = new Symfony\Component\Process\Process('php -r "echo 123; exit(0);"');
$threadManager->addThread($process);
Add thread object.
$threadManager->addThread(
\FGhazaleh\MultiThreadManager\Thread::createFromCommand(
'php -r "echo 123; exit(0);"'
)
);
Add thread with context.
$threadManager->addThread('php -r "echo 123; exit(0);"', ['data' => 'some data']);
$threadManager->wait();
$threadManager->terminate();
Register event with class listener.
$threadManager->listen(
\FGhazaleh\MultiThreadManager\Contracts\EventInterface::EVENT_STARTED,
new JobStartedListener()
);
$threadManager->listen(
\FGhazaleh\MultiThreadManager\Contracts\EventInterface::EVENT_FINISHED,
new JobFinishedListener()
);
$threadManager->listen(
\FGhazaleh\MultiThreadManager\Contracts\EventInterface::EVENT_TIMEOUT,
new JobTimeoutListener()
);
...
$threadManager->addThread(...)
Register event closure listener function.
$threadManager->listen(
\FGhazaleh\MultiThreadManager\Contracts\EventInterface::EVENT_STARTED,
function (\FGhazaleh\MultiThreadManager\Contracts\ThreadInterface $thread){
...
}
);
if you discover a security vulnerability within this boilerplate, please send an email to Franco Ghazaleh at franco.ghazaleh@gmail.com, or create a pull request if possible. All security vulnerabilities will be promptly addressed. Please reference this page to make sure you are up to date.
This project is licensed under the MIT License.