iumesh's avatar

How to return response and continue executing script in laravel without queue

Hi am trying to develop a project in which we get a lot of data from android devices and i want to return response to device after file upload and then do processing, the processing takes time and the device number are huge hence i want to do it without queueing. So that i can process data quickly.

0 likes
7 replies
ohffs's avatar

I think sending a header with an http status of 202 is sometimes done, if that's what you mean?

iumesh's avatar

will it close the http connection and i need to send a message so that it can know that the file is received

pmall's avatar

You cant return a response and keep the script running. This is a problem solved by queues, you have to use them.

1 like
ohffs's avatar

You can return the output directly rather than use the $response though, eg :

<?php
header("HTTP/1.1 202");
ob_flush();
flush();
for($n=0; $n < 10000000; $n++) {
    $y=cos(rand());
}
echo $n;

But, yeah, it's nasty ;-) @umesh you can have a read of http://farazdagi.com/blog/2014/rest-long-running-jobs/ which should help you hopefully.

iumesh's avatar

@ohffs @pmall thanks for you response

@ohffs the solution you suggested i already implemented it but the apache instance managing this request will keep running until the execution completed.

I guess separating the job and queuing it is only way is it possible to use multiple queues and use a scheduler to manage them i.e for example having 10 queue which do the same job and when a job come you assign it to queues based on some parameter that defines effective distribution between them.

pmall's avatar

I guess separating the job and queuing it is only way is it possible to use multiple queues and use a scheduler to manage them i.e for example having 10 queue which do the same job and when a job come you assign it to queues based on some parameter that defines effective distribution between them.

I guess this is handled at the queue manager level (if you want to run jobs in parallel or one after another)

Please or to participate in this conversation.