Ste*_*rig 19
您可以使用锁定来确保命令一次只运行一次.Symfony LockHandler为此提供了帮助,但您也可以使用普通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;
}
// ... do some task
$lock->release();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2067 次 |
| 最近记录: |