Setting up queues requires, as the very first step, to choose what driver you'll be using. Because it's the quickest to get running, I'll explain how to begin with the database
driver, as it doesn't require any other services to be installed on the server (as it's the case for beanstalkd
for example). Here's how to get this set up:
1. Set the QUEUE_DRIVER
in your .env
file:
QUEUE_DRIVER=database
2. Run this command to generate the migration file for the jobs
table, that will be used to store job information:
php artisan queue:table
3. Now run the migration to create the table:
php artisan migrate
A jobs
table was created that will store data when jobs are pushed on the queue.
You can push both commands and clojures onto queues. For the sake of brevity, I'll show an example of how to push a closure onto a queue:
$username = Request::input('username');
$password = Request::input('password');
// Do your registration stuff
// Push a job onto the queue
\Queue::push(function($job) use ($username, $password)
{
// Do the stuff you need here with $username and $password
// Delete the job from the queue
$job->delete();
});
The final step to making this work is to run the queue listener. Jobs will not be processed automatically unless the queue listener is running. So run this command:
php artisan queue:listen
There are further steps you can take, such as setting up Supervisor to monitor and restart the queue listener should it crash, but this should be enough to get you started.