What could cause a high TTFB on a WordPress website

Your website has a high TTFB (time to the first byte) and you don’t know how to find the root cause?

If this is your case I will tell you the steps I do to find the root cause.

If the TTFB is too high, it means that the time needed by PHP to build the HTML output plus the time needed by the server to send back the output to the browser is too high.

Let’s first understand if it’s a matter of PHP or server/browser connection time.

We can check the connection time just by measuring the speed of a simple HTML file on the same server.

Because you have WordPress you will surely have the readme.html file at https://your-domain.com/readme.html or at https://your-domain.com/your-sub-folder in case WordPress is installed in a subfolder.

So measure the loading time of your readme.html file, using e.g. Pingdom or GTMetrix or whatever speed tool you like.

If your server has no connection problems, the readme.html file should load in not more than 0.4 seconds.

Perform a couple of tests, if you always see a loading time between 0.2 and 0.4, I would say that the connection is ok and we can pass to analyze the PHP performance.

As you probably already know, PHP is the programming language used by WordPress to build the final HTML output.

Before writing the HTML, PHP makes some queries to the database to fetch the needed information.

If some PHP scripts are very badly coded or ask too many slow queries to the database, the PHP parser will need a long time before building the HTML.

Until the HTML is ready, the server will not send the page to the browser.

What is in WordPress that could introduce bad PHP scripts and/or too many slow database queries?

WordPress core itself, the plugins, and the theme.

Let’s exclude the first one, we are using WordPress and we are sure that the WordPress core team writes clean code. But we don’t completely trust all the plugins we have installed and we have some doubts also about the theme.

First, let’s see if the cause comes from the plugins, so let’s deactivate all plugins and see if the TTFB is better.

To deactivate all the plugins, just rename the plugins folder.

Now you will have 2 possibilities: the TTFB is really better, the TTFB is not a lot better.

In the first case, you have discovered that one of your plugins is guilty. In the second case, you start to suspect the theme.

Now we suppose that one of the plugins is guilty. If so you should activate again all plugins and deactivate a plugin after the other until you find the guilty.

If you find it, you should decide what to do with the bad plugin: replace it with another one having similar functionalities, write to the plugin author, investigate deeper trying to find out why that plugin increases the TTFB.

If after disabling all plugins you hadn’t found a big difference in terms of TTFB, it would be a good idea to switch to the default WordPress theme.

If with the default WordPress theme (that we consider well coded) you still notice a high TTFB, it means that neither the plugins nor the themes are causing the issue.

If you are at this point, it means that the PHP and/or MySQL performance are not good or that your database needs optimization.

First, check the PHP version it’s running on your server and be sure that you have the most updated stable version. If you don’t have old plugins causing compatibility issues, it’s always a good idea to have the last PHP version for both performance and security reasons.

But you are still here, your plugins are all ok, your theme is ok, you have the last PHP version, the server connection has no problems, so now? Could it really be the PHP performance? Or the database?

Between these last two options, I would first check the database.

If you have many products, posts, comments … your database may need some optimization.

If this is your case I suggest you clean your database deleting all the posts and pages you have in the trash, spam comments, posts revisions, database tables left by removed plugins …

To accomplish it you could use e.g. the plugin Advanced Database Cleaner or similar plugins.

If after all these actions you still have a high TTFB, you could still have this kind of problems:

  • Misconfigured web server (Apache, Nginx, PHP, MySQL)
  • The origin server reached its capacity (CPU, memory, disk …)

If your web site is hosted on a shared server or you simply don’t feel confident with server settings, contact the server customer service and explain all the tests you have done.