php – Laravel队列无法正常工作
作者:互联网
我正在使用laravel队列在facebook帖子上发表评论.什么时候我收到facebook webhook的数据,基于收到的细节我
评论帖子.要从facebook webhook一次处理100个响应,我正在使用laravel队列,以便它可以逐个执行.
我已经使用了https://scotch.io/tutorials/why-laravel-queues-are-awesome中提到的分步流程
public function webhooks(Request $request)
{
$data = file_get_contents('php://input');
Log::info("Request Cycle with Queues Begins");
$job = (new webhookQueue($data)->delay(10);
$this->dispatch($job);
Log::info("Request Cycle with Queues Ends");
}
这是我的工作类结构
class webhookQueue extends Job implements ShouldQueue
{
使用InteractsWithQueue,SerializesModels;
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文件中你应该将queue_driver从同步更改为数据库,
如此开放.env并做以下
queue_driver=database
之后,您应该使用artisan命令在数据库中创建队列表:
php artisan queue:table
php artisan migrate
最后你应该用php artisan队列运行你的队列:listen或php artisan queue:work
标签:php,laravel,webhooks 来源: https://codeday.me/bug/20191006/1857958.html