Queues and Redis Setup 0:00Queues with Laravel allow you to push time-consuming tasks onto a background job where they will be processed by a queue worker. To make use of this with Laravel Forge, I want to demonstrate this by adding a job to our simple CRUD application. So in this example application, I can add new posts, and every time I create a post, I will dispatch a job onto the queue where I'm just going to log something in the background. So in order to make use of queues, you have to meet some prerequisites. It depends a bit on which queue driver you want to use. So in my case, I want to use Redis for my queues, and in order to make use of Redis on my server, I need to install a PHP library which is called Redis. Creating and Dispatching Jobs 0:44So in my case, I want to use Redis for my queues, and in order to make use of Redis on my server, I need to install a PHP library which is called Redis. So in the Laravel documentation, you can see the prerequisites for each of the drivers that you can use, and just make sure to install this package with Composer. So I already installed the package, here it is, and in my post controller, every time I store a post, I dispatch a new job, which is called postCreated, and this job implements the shootQueue interface, so that Laravel knows to put this job on the queue. And in the handle method you see, it does nothing really special, it just logs a string into the Laravel log file. Okay, so now to use this on our Laravel Forge servers, we need to configure a queue worker. Configuring Forge Queue Worker 1:41into the Laravel log file. Okay, so now to use this on our Laravel Forge servers, we need to configure a queue worker. Queue workers are defined per site, so if I go to my default site, which is the one that I use for this example application, I can configure multiple workers. So let's take a look at the parameters that we can specify step by step. So first is the connection. As I said in my example, I'm going to use Redis, but if you use something else, maybe Beanstalk, you can just change the setting here. The queue that we will run and use to work the jobs off is the default queue, so if you have multiple queues, you can define them here.The queue that we will run and use to work the jobs off is the default queue, so if you have multiple queues, you can define them here. Next we have the maximum seconds per job, so this is the timeout, the amount of time that each individual job may run before it fails. Then we have 10 seconds that we rest before we try looking for new jobs in our queue. If the job fails, you can specify a failed job delay, so this means that you wait for a certain amount of seconds before retrying a failed job again. We have one process that will be spawned to work the queues, we have a maximum number of three tries, and we will run this in production mode. And last but not least, we have this little checkbox down here, where we can say that Daemon Mode and Deploys 3:15of three tries, and we will run this in production mode. And last but not least, we have this little checkbox down here, where we can say that we want this queue worker to run as a daemon. So by using as a daemon, it means that it does not boot the framework every time you run a queue worker. If you use this option, just be sure to use phpArtisanQueueRestart in your deployment script, because otherwise the queue worker will not pick up the latest code changes. So for our example use case, we can just stick with the default values here and start the worker. And here at the bottom, you see a list of all the active workers that you have for the Testing and Verifying Logs 4:01the worker. And here at the bottom, you see a list of all the active workers that you have for the current site. Alright, now to give this a try, I can go to my example application and create a new post. So the title will be Forge Demo, the content Forge Queues are Great, and we're going to save this. Now in the background we pushed the job to a queue which will log something into our Laravel log file. So to verify that it actually worked, let's go to our server and check the log file.Laravel log file. So to verify that it actually worked, let's go to our server and check the log file. I'm already connected via SSH on my server, so let's take a look at the log file. And there it is. This is the info that the job was successfully processed by our queue worker. So with Laravel Forge, defining and configuring multiple queue workers is really easy, and you can also check the status of them, restart them, or remove them through the admin interface.