You can use a lock to ensure that a command is run only once at a time. Symfony provides an assistant LockHandler, but you can also easily do this with simple PHP.
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\LockHandler;
class WhateverCommand extends Command
{
protected function configure() { }
protected function execute(InputInterface $input, OutputInterface $output)
{
$lock = new LockHandler('a_unique_id_for_your_command');
if (!$lock->lock()) {
$output->writeln('This command is already running in another process.');
return 0;
}
$lock->release();
}
}
source
share