Laravel Cache is mandatory

I was configuring a Laravel 5.7 application, and had a Queue with an Amazon SQS driver.

Laravel built-in cache was NOT used explicitly by the application, so I pointed it to a non-existent Redis host. This will be important later.

To my surprise, when running the queue worker, the application was fataling as it was trying to use Redis and was failing to connect.

My first reaction was to think that maybe the queue was misconfigured to consume from Redis and not from SQS. However the stacktrace clearly showed some SQS related code.

Digging further, I found out that the internal workings of the Laravel queue worker internally depend on the Laravel built-in cache to store when the queue was last restarted. Relevant snippet from Laravel internals below:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    /**
     * Get the last queue restart timestamp, or null.
     *
     * @return int|null
     */
    protected function getTimestampOfLastQueueRestart()
    {
        if ($this->cache) {
            return $this->cache->get('illuminate:queue:restart');
        }
    }

This is probably not the only place where Laravel internals depend on its Cache.

Lesson learned:

Even though your application may not explicitly leverage the Laravel built-in cache, the framework does, so make sure a vialble cache is configured in production.