Fix: Timeout Errors in WordPress

Don’t give up! Timeouts are really annoying with WordPress, but also very common. It’s better to learn how to deal with them, and understand why they occur.

The Timeout Errors

Depending on the server and where the timeout occurs on the network, the exact error might be slightly different even though the cause it always the same annoying one! 😬

408 Request Timeout

This code means that the server shut down an unused connection.

Error 524: A timeout occured

Error 524 error indicates that Cloudflare made a successful TCP connection to the origin web server, but the origin did not reply with an HTTP response before the connection timed out. Typically, Cloudflare waits 100 seconds for an HTTP response. If the origin doesn’t respond in that time, Cloudflare closes the connection and you’ll see “Error 524: A timeout occurred”.

504 Gateway Timeout

This code indicates that a gateway or a proxy did not get a response in time from your server.

Why does it happen?

Your WordPress didn’t reply fast enough, and your server decided to the request. Usually, most servers are set up to kill requests when they exceed 30 seconds, and it’s actually not a bad choice : they shouldn’t take that much time.

Okay, but why is WordPress so damn slow? Well, for every single request (including asynchronous ones), WordPress loads itself, but not only: all the plugins also initialize themselves! And some of those plugins can decide to perform a specific action or task, like an update check, or worse. Everything is possible.

How to fix timeout errors?

There are basically two solutions: optimize, or increase the max execution time. The former is my recommendation.

Optimize your WordPress install

That’s what you should absolutely do. Make sure you use the latest version of PHP (or at least PHP 7.3+). Then, check the plugins currently active on your WordPress and try to disable the ones you don’t absolutely need. You can follow this tutorial to make sure your WordPress is as fast as it should be: How to: Make WordPress Faster & Optimize It.

Database Cleaner for WordPress

While you are here; having a very snappy and healthy database is also really important. For that, you can give a quick try to Database Cleaner. It might help you a lot, enough to get rid of your timeout!

Increase the Max Execution Time

There are many ways to do this. However, you might not be able to do this by yourself if it’s not your own server. It’s usually better to contact your hosting service to do this. But just in case, let’s see two ways of extending the maximum execution time.

By modifying your PHP Settings

That’s not easy, as you need to have access to your server, or a way to change your PHP settings. If you have access to your php.ini, you need to look for the max_execution_time variable and set it to the number of seconds you would like, 60 seconds for example.

max_execution_time = 60

If that doesn’t work, or can’t access your php.ini, you can also try to set this variable by using the .htaccess (at the root of your WordPress install). You can add this line.

php_value max_execution_time 60

If you set the value to 0 (instead of 60, here), the process will be allowed to run forever. Don’t do this, you will run into much bigger issues, extremely difficult to resolve.

By modifying your server settings

NGINX

You could try this:

fastcgi_read_timeout 600;
fastcgi_send_timeout 600;
fastcgi_connect_timeout 600

By calling a function in PHP

This is generally not really recommended to do this. But if you know what you are doing, you can tell PHP that you would like the process to run for more time. For this, you could write this call in your theme, in the functions.php for example.

set_time_limit(100);