简体   繁体   English

Symfony Cron工作,奇怪的错误

[英]Symfony cron job, strange error

I have this symfony command that runs well locally and on the server. 我有此symfony命令,该命令在本地和服务器上运行良好。 Locally, it works if I call it or if it goes through cron. 在本地,如果我调用它或通过cron,它就可以工作。

On the server side, it works if I call it on the shell window, but the moment cron calls it, it doesn't wanna work and throws me this strange error. 在服务器端,如果我在shell窗口中调用它,它将起作用,但是在cron调用它的那一刻,它不起作用,并抛出了这个奇怪的错误。

the command is php ~/mg/app/console global:insert 1 -vv --env=prod 该命令是php ~/mg/app/console global:insert 1 -vv --env=prod

And the error is 错误是

ContextErrorException in ArgvInput.php line 287: Warning: Invalid argument supplied for foreach()

in ArgvInput.php line 287
at ErrorHandler->handleError('2', 'Invalid argument supplied for foreach()', 'vendor/symfony/symfony/src/Symfony/Component/Console/Input/ArgvInput.php', '287', array('values' => array('--ansi'))) in ArgvInput.php line 287
at ArgvInput->hasParameterOption(array('--ansi')) in Application.php line 823
at Application->configureIO(object(ArgvInput), object(ConsoleOutput)) in Application.php line 123
at Application->run(object(ArgvInput)) in console line 26

Your help would be greatly appreciated, first time I ever see this error message. 您的帮助将不胜感激,这是我第一次看到此错误消息。

Command code 指令码

class GlobalInsertCommand extends ContainerAwareCommand
{
protected function configure()
{
    $this
        ->setName('global:insert')
        ->addArgument('env', InputArgument::OPTIONAL, '1 | 0',0);
}

protected function execute(InputInterface $input, OutputInterface $output) {

    $rootDir = $this->getContainer()->get('kernel')->getRootDir();

    foreach (MyRepos::$SOURCES as $source):
        if($input->getArgument("env") == 1):
            $source .= " --env=prod";
        endif;
        MyRepos::runProcess("php $rootDir/console immobilier:insert $source -vv");
    endforeach;
}

} }

The actual insertCommand 实际的insertCommand

class InsertCommand extends ContainerAwareCommand {


protected function configure()
{
    $this
        ->setName('immobilier:insert')
        ->setDescription('Take RawData and and insert into database')
        ->addArgument('source', InputArgument::REQUIRED, 'all')
    ;
}

protected function execute(InputInterface $input, OutputInterface $output) {
    $this->pc = $this->getContainer()->get('Momoa.immobilier_cron.controller');
    try {
        $this->pc->setChoice($input->getArgument("source"));
        $this->pc->addAction();
    } catch(Exception $e){
          $this->logger->error($e->getMessage());
    }
}

} }

And the Run Process method 和运行过程方法

    static function runProcess($command){
    $ps = new Process($command);
    $ps->enableOutput();
    $ps->setTimeout(null);
    $ps->run(function($type, $buffer) {
        echo "OUT > " . $buffer;
    });
}

So I found the problem, The error is not related to the actual logic of the command file but the php.ini options. 所以我找到了问题,该错误与命令文件的实际逻辑无关,但与php.ini选项有关。

First you need to be sure that this option is set to on register_argc_argv=on in your php.ini file. 首先,您需要确保在php.ini文件中的register_argc_argv=on将此选项设置为on。

If you can't change your php.ini file, declare the command as such: 如果您无法更改php.ini文件,请这样声明该命令:

php-cli -d register_argc_argv=On /path/to/your/command

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM