1

I have used the queue job in my Laravel project to send emails to multiple users. My code is working perfectly on the local system, but on the production server, when I run the queue:work command, it shows a 504 Gateway Timeout error and the server is crashing.

How to solve this problem on the production server?

2
  • What is your mailing configuration on production? have you tried to send an email manually on production? Commented Apr 2 at 8:22
  • What's your queue configuration in your production server? You need to properly configure that. Commented Apr 2 at 10:58

1 Answer 1

1

As mentioned in the laravel docs, you need to use a different tool to keep your queue:work command up and running.

Here are some checklists for preparing your queue:

  1. Is your QUEUE_DRIVER environment variable set to the proper driver? (such as redis or sqs)
  2. Have you installed supervisor and configured the process to run php artisan queue:work?
  3. Have you checked how long the queue process time takes?

For No 1, sync is great for local development, but it's not executing in the background so it's not suited for actual production use. You must change it to other queue driver.

For No 2, you can try following this gist for reference.

For No 3, this is to ensure that your job's execution time is well within the allowed execution time of the queue. If I remember correctly, laravel's default queue timeout is 60 seconds, and if the execution goes over 60s, the job will fail prematurely and your email sending will be cutoff. To solve No 3, you will have to optimize the code for shorter execution, or extend the max execution time to be longer.

Hope this helps.

Regards,

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.