尝试让队列在我的共享主机上运行,
php artisan队列:在我的共享主机上工作(通过cron)返回
[ErrorException]
Invalid argument supplied for foreach()
在我的日志文件中写入以下内容。
[2015-04-12 18:59:01] production.ERROR: exception 'ErrorException' with message 'Invalid argument supplied for foreach()' in /home/a109/vendor/symfony/console/Symfony/Component/Console/Input/ArgvInput.php:287 Stack trace:
#0 /home/a109/vendor/symfony/console/Symfony/Component/Console/Input/ArgvInput.php(287): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Invalid argumen...', '/home/a109/vend...', 287, Array)
#1 /home/a109/vendor/symfony/console/Symfony/Component/Console/Application.php(823): Symfony\Component\Console\Input\ArgvInput->hasParameterOption(Array)
#2 /home/a109/vendor/symfony/console/Symfony/Component/Console/Application.php(123): Symfony\Component\Console\Application->configureIO(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /home/a109/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(94): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /home/a109/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 {main}
在vendor / symfony / console / Symfony / Component / Console / Input / ArgvInput.php的第287行有这个函数
/**
* Returns true if the raw parameters (not parsed) contain a value.
*
* This method is to be used to introspect the input parameters
* before they have been validated. It must be used carefully.
*
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
*
* @return bool true if the value is contained in the raw parameters
*/
public function hasParameterOption($values)
{
$values = (array) $values;
foreach ($this->tokens as $token) {
foreach ($values as $value) {
if ($token === $value || 0 === strpos($token, $value.'=')) {
return true;
}
}
}
return false;
}
那是失败的傻逼。
我怎样才能让它发挥作用?
答案 0 :(得分:10)
我必须将cron命令更改为:
php -d register_argc_argv=On artisan queue:work
答案 1 :(得分:0)
从Laravel 5.7开始,有一个新的队列命令在空时停止工作:
;
由于这仅适用于大多数电子邮件或少量工作,因此我将其放在cronjob上,以便每分钟运行一次。我说这并不是每分钟超过20个工作的解决方案,但可以处理我的电子邮件。仅发送一封电子邮件,这将每分钟运行大约5秒钟,具体取决于发送的电子邮件数量。
php artisan queue:work --stop-when-empty
$ php artisan make:command SendContactEmails
中,更改:SendContactEmails.php
protected $signature = 'emails:work';
方法中,添加:handle()
return $this->call('queue:work', [
'--queue' => 'emails', // remove this if queue is default
'--stop-when-empty' => null,
]);
文件中,将命令添加到您的命令列表中:app/Console/Kernal.php
protected $commands = [
\App\Console\Commands\SendContactEmails::class
];
protected function schedule(Schedule $schedule)
{
$schedule->command('emails:work')->everyMinute();
// you can add ->withoutOverlapping(); if you think it won't finish in 1 minute
}
处理所有排队的作业然后退出
* * * * * /usr/local/bin/php /home/username/project/artisan schedule:run > /dev/null 2>&1
选项可用于指示工作人员处理所有作业,然后正常退出。如果您希望在队列为空后关闭该容器,请在Docker容器中处理Laravel队列时使用此选项:
--stop-when-empty