php - Symfony cron 作业,奇怪的错误

我有一个在本地和服务器上运行良好的 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;
}

实际的插入命令

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

和Run Process方法

    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 文件中将此选项设置为 on register_argc_argv=on

如果您不能更改 php.ini 文件,请这样声明命令:

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

https://stackoverflow.com/questions/29783473/

相关文章:

sql - 使用当前连接从 sql 存储过程调用 dll 函数

sql - 如何在外键约束中使用两列

python - 列出目录中的所有文件 - 按大小过滤

css - padding-top 不起作用,但 padding-right 是

asp.net-mvc - 如何在 web.config 中设置密码和用户名

java - String.split() 如果在字符串的最后部分,则忽略定界符之间的空值

logging - 日志不打印完整的堆栈跟踪

ruby - 我在哪里可以看到我的浏览器发送的 http 请求

sql-server - 在任务管理器中误杀了sqlserver.exe进程,如何重启?

macos - 将 MAC 上远程桌面中的下移控制向下箭头发送到 Windows PC