[英]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.