You can run a Redis queue to optimise performance in the control panel when using the Git integration. With any form of queue driver you can also push other tasks, like generating assets or warming the static cache, into the background. A queue performs jobs in the background. This makes sure that you don't have to wait for tasks when browsing the control panel or when you're deploying your website. This article explains how you can make a Redis queue work for multiple Statamic sites on one server.
For Statamic to use a Redis queue you only have to change some environment values.
The environment variables involved.
redis and instruct Redis which database to use with
REDIS_DATABASE. When you configure your server with a tool like Ploi or Forge, Redis is automatically installed and it comes with 16 databases by default. Every site on your server has to use its own database. This means for every site you pick a number between 0 and 15 and you don't use the same database twice.
When your server grows and contains more site it can become a chore to keep track of which site is using which database number and to figure out which numbers are currently available. Ploi has a handy notes field in the servers settings tab where you could keep track of that. This is what I do.
Starting a queue worker
For each site on your server using Redis you have to start a queue worker. This is a server process that keeps track of all the jobs entering the queue and executing them. Starting a worker is very simple within Ploi. This works similar when using Forge. Go to the queue tab for your current site and configure the worker.
Make sure you set the the
redis and the
environment to your current environment. Hit the button and that's it.
Whenever tasks fail it can be a little tricky to debug. Redis expects your site to run a MySQL database so it fills up your Laravel log with SQL connection errors. The actual reason your job is failing won't be listed. Jonas Siewertsen wrote an excellent and lightweight package you can install that saves the actual failed queue job errors in a log file. As an alternative you could also install Laravel Horizon. It comes with a GUI where you can see all kinds of information about running queues. You have to install this on a per site basis.
That's how to use a Redis queue together with Statamic. If you have any questions or thoughts please let me know.