当前位置:   PHP > 正文

Symfony2 - 检查命令是否正在运行

symfony,php,DevBox,在线流程图,编程,编程问答,程序员,开发者工具,开发工具,json解析,二维码生成,unix时间戳,在线开发工具,前端开发工具,开发人员工具,站长工具

有没有办法检查symfony命令是否已经运行?我有一个没有超时运行并消耗数据的命令,我需要知道命令是否已经运行.



1> Stefan Gehri..:

您可以使用锁定来确保命令一次只运行一次.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();
    }
}

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号