![](/img/trans.png)
[英]Iron.io Push Queue and Laravel 4 - preventing the queue request from running multiple times
[英]Laravel Iron Queue::push doesn't seem asynchronous
我有一个表单,允许用户输入一些文本并上传图像(然后调整图像大小并发送到TinyPNG.com进行优化)。 单击提交按钮后,表单通过JQuery AJAX发送数据。 在数据发布完成后,我想通过AJAX函数中的On Success向用户显示一些消息,但不等待图像处理过程。 为此,我使用Iron创建了一个Laravel队列,代码如下:
\Queue::push('RenameClassImage',[$_POST['temp_img_id'], $class_id,$final_path,$_POST['crop_w'],$_POST['crop_h'],$_POST['crop_x'],$_POST['crop_y']]);
总体来说一切正常,除了AJAX成功函数只在整个图像处理过程完成后触发(这需要很长时间)。
下面是我的队列配置文件。 如果您希望我包含任何其他代码,请告诉我们。 提前致谢
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Queue Driver
|--------------------------------------------------------------------------
|
| The Laravel queue API supports a variety of back-ends via an unified
| API, giving you convenient access to each back-end using the same
| syntax for each one. Here you may set the default queue driver.
|
| Supported: "null", "sync", "database", "beanstalkd",
| "sqs", "iron", "redis"
|
*/
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'ttr' => 60,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'queue' => 'your-queue-url',
'region' => 'us-east-1',
],
'iron' => [
'driver' => env('QUEUE_DRIVER'),
'host' => env('QUEUE_HOST'),
'token' => env('QUEUE_TOKEN'),
'project' => env('QUEUE_PROJECT'),
'queue' => env('QUEUE_NAME'),
'encrypt' => true,
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'expire' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Failed Queue Jobs
|--------------------------------------------------------------------------
|
| These options configure the behavior of failed queue job logging so you
| can control which database and table are used to store the jobs that
| have failed. You may change them to any database / table you wish.
|
*/
'failed' => [
'database' => 'mysql', 'table' => 'failed_jobs',
],
];
在.env
文件中,您必须设置队列:
QUEUE_DRIVER=iron
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.