簡體   English   中英

Symfony Cron工作,奇怪的錯誤

[英]Symfony cron job, strange error

我有此symfony命令,該命令在本地和服務器上運行良好。 在本地,如果我調用它或通過cron,它就可以工作。

在服務器端,如果我在shell窗口中調用它,它將起作用,但是在cron調用它的那一刻,它不起作用,並拋出了這個奇怪的錯誤。

該命令是php ~/mg/app/console global:insert 1 -vv --env=prod

錯誤是

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

您的幫助將不勝感激,這是我第一次看到此錯誤消息。

指令碼

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;
}

}

實際的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());
    }
}

}

和運行過程方法

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

所以我找到了問題,該錯誤與命令文件的實際邏輯無關,但與php.ini選項有關。

首先,您需要確保在php.ini文件中的register_argc_argv=on將此選項設置為on。

如果您無法更改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