Fix: Timeout Errors in WordPress

Those timeouts really depends on your WordPress install and your server. In fact, there are many different errors meaning that a timeout occured, and they are all slighlty different.

The Timeout Errors

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?

For each page load, or for each asynchronous requests, WordPress loads itself every time. It doesn’t sound very productive, but this is how PHP works. Therefore, all the plugins are loaded every time. They also sometimes perform tasks, check updates, etc. You understand how much important it is to optimize your WordPress.

Generally, servers kill requests when they exceed 30 seconds. Nothing else will be displayed to you, the connection will just be cut.

How to fix timeout errors?

There are a few solutions.

Optimize your WordPress install

In short, make sure you are using the latest version of PHP (at least, PHP 7), and that you are running the least amount of plugins. You can follow this tutorial to make sure your WordPress is as fast as it should be: How to: Make WordPress Faster & Optimize It.

Increase the Max 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 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);