I have a web application written using Laravel 4 that runs a script when a user requests a certain page or clicks a button. This should activate the script in the background.
Currently, my setup looks like this,
Controller portion:
public function getWorkerPage() {
Queue::push('UpdateUserVar1', array('id' => $login->id));
Queue::push('UpdateUserVar2', array('id' => $login->id));
Queue::push('Worker', array(
'login_id' => $login->id
));
.... // Some more stuff
View::make('workerpage');
}
Worker:
class Worker {
public function fire($job, $data) {
...
//Process (Takes around 10 minutes)
// Release the job which makes the worker work until it deletes itself by a piece of logic in the Process bit above.
$job->release();
}
}
Now, my whole problem is that when more than one user requests this script to be run, it takes 10 minutes before the previous job is finished. I don't want that. I would like those scripts to just run in the background until the user stops it. And when the user requests the script to be run, that it just runs immediately.
I guess I need to take away the queue then but my problem then is, is that the page will keep loading loading and that's not something that I want either since after the Queue::push
's, there is a normal View. So I'm searching for a PHP program or a function that lets me execute the script, pass in a couple variables and that without blocking the rest of the code in the Controller.
I did find some solutions like Gearman and Supervisord but I couldn't really judge if these were options for me since I didn't quite grasp the documentation.
If something is not totally clear about my question, please do not hesitate to ask.
Nutshell: I need a program that executes my script in the background and enables me to keep using Laravels function and pass in variables without blocking the code after the program execute.