Php Laravel队列不工作
我正在使用laravel队列对facebook帖子进行评论。当我从facebook webhook收到数据时,根据我收到的详细信息 评论这篇文章。为了一次处理来自facebook webhook的100个响应,我使用了laravel队列,这样它就可以逐个执行。 我使用了中提到的逐步过程 这是我的职业班结构Php Laravel队列不工作,php,laravel,webhooks,Php,Laravel,Webhooks,我正在使用laravel队列对facebook帖子进行评论。当我从facebook webhook收到数据时,根据我收到的详细信息 评论这篇文章。为了一次处理来自facebook webhook的100个响应,我使用了laravel队列,这样它就可以逐个执行。 我使用了中提到的逐步过程 这是我的职业班结构 class webhookQueue extends Job implements ShouldQueue { 使用InteracticsWithQueue,序列化模型 private $d
class webhookQueue extends Job implements ShouldQueue
{
使用InteracticsWithQueue,序列化模型
private $data;
public function __construct($data)
{
$this->data = $data;
}
public function handle()
{
//handling the data here
}
}
我一直在使用webhooks()函数,所有作业都在同时工作,但不在队列中,没有一个作业存储在作业表中,我给了延迟,但它也不工作,请有人帮助我,我从昨天开始一直在尝试,但没有结果
这是我在laravel.log中的日志
[2017-02-08 14:18:42] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:44] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:47] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:47] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:47] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:47] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins
[2017-02-08 14:18:55] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:18:55] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:18:55] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:18:59] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:19:00] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:19:00] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:19:00] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends
为了使用队列,您应该做一些工作: 在.env文件中,您应该将队列驱动程序从同步更改为数据库, 所以打开.env并执行以下操作
queue_driver=database
之后,应使用artisan命令在数据库中创建队列表:
php artisan queue:table
php artisan migrate
最后,您应该使用
php-artisan-queue:listen
或php-artisan-queue:work
运行队列。我发现您已经有了队列表
尝试运行php artisan队列:listen--trys=3
或php artisan队列:work
等
队列工作用于每个命令只执行一个作业。因此,如果表中有20个作业,您可能需要运行队列工作20次。这就是为什么您可以运行queue:listen
命令。但是它占用了很多CPU
在服务器中,您可能希望在后台以最多3次尝试的方式运行队列侦听。
在终端/命令提示符中使用SSH连接到服务器。然后将CD
复制到artisan文件所在的项目目录。运行以下命令:
nohup php artisan队列:侦听--trytes=3>/dev/null 2>&1&
在这种情况下,作业将自动在后台处理。你只要把工作分派出去就行了。我建议使用失败作业表。如果您使用的是后台队列列表器
希望这能有所帮助。Laravel 5.7的更新: 在
.env
中,设置QUEUE\u CONNECTION=database
,以便调度的作业转到数据库驱动程序
然后:
我也遇到了同样的问题,如果您使用的是Laravel5.7,请在.env文件中使用它
QUEUE_CONNECTION=database
之后,像这样清除配置缓存
php artisan config:cache
被接受的答案对我来说是一个问题,但我也解决了另外两个类似的问题,也许他们会帮助其他来到这里的人 其他问题1:创造工作(构造器)是可行的,但作业处理程序不会启动-始终
- ever在这里很关键,因为通常情况下,如果它们都没有触发,那么这可能是因为作业代码被修改,队列应该重新启动
- 如果有时对您来说是正确的,那么您的作业没有被触发可能是因为它们发生在事务中,比如
李>DB::beginTransaction
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($errorInfo)
{
$this->errorInfo = $errorInfo;
// Queues won't run the handlers during transactions
// so, detect the level, and if it is not 0, rollback to force job handling
if (\DB::transactionLevel() != 0) {
\DB::rollBack();
}
}
但不要这样做,除非你想解雇你的工作并强制回滚。我的情况是独一无二的,因为我的工作发送致命错误的电子邮件,所以我希望它启动,因为我有一个错误破坏了进程(回滚即将发生,并且由于未捕获的错误而未计划)
在这种情况下,您可能不想这样做:
- 付款成功时,您的作业会向用户发送电子邮件
- 您的付款可能成功,但无法成功
- 根据成功付款,您可以回滚或提交
我不确定在事务中触发作业,然后回滚或提交的行为。如果它不能正常工作,可以通过添加延迟来解决,但这似乎不可靠(猜测等待的时间),除非它是一个明显的延迟。对于这些问题的未来读者,如果队列以前工作过,但现在不再工作了,请尝试删除数据库中jobs表中的所有内容,这对我很有用。确保你的应用程序未处于维护模式。。。我在维护我的,但允许我的本地ip地址。。。我不明白为什么它没有运行。我最后不得不去调试WorkCommand来找出
一个工匠站起来 不要犯和我一样的错误 我在错误的目录中运行了
php artisan queue:work
只浪费了30分钟,可能会更长。在我的例子中,我使用自定义队列名称来组我的作业
ProcessCourseInteractions::dispatch($courseProcessing)->onQueue('course_interactions');
该队列不是由以下人员执行的:
php artisan queue:work
及
我需要指定队列名称(对工作和侦听有效):
只需在.env文件中设置
QUEUE\u CONNECTION=database
所有设置都已设置,但仍不起作用,然后确保在crontab-e上添加了时间表
QUEUE_CONNECTION=database
***cd/var/www/html/&&php artisan schedule:run>/dev/null 2>&1
您可以按以下方式重试(我假设您在Laravel文档中执行了说明,但有一天它不起作用):
步骤1:在数据库中删除表“作业”
步骤2:在控制台中运行命令“php artisan migrate”,再次创建表“jobs”
步骤3:在控制台中运行命令“php artisan队列:工作”
步骤4:重试你的应用程序
请注意,在.env文件中,您可以设置:
队列连接=数据库
队列驱动程序=da
php artisan queue:work
php artisan queue:listen
php artisan queue:work --queue=course_interactions