Symfony console command lockable trait (very simple emulation of multithreading)
Add this to composer.json
{
"require": {
"devcreel/command-lockable-trait": "1.0.*-dev"
}
}
<?php
namespace TestBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use DevCreel\Command\LockableTrait;
class TestCommand extends ContainerAwareCommand
{
use LockableTrait;
//count of threads
private $threadsCount = 5;
protected function configure()
{
$this->setName('test:run');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
//check for free thread
if (!$this->lock()) {
$output->writeln('[' . $this->getName() . '] is already running in another process.');
return 0;
}
//your code...
//release thread
$this->release();
}
}
CommandLockableTrait is licensed under the MIT License