Performance and monitoring

PHP X-Ray: find what makes your site slow, step by step

Reviewed on 4 min read PHP X-Ray performance

Working out why a site is slow or what is causing high CPU usage can be very difficult. X-Ray makes it simpler: for a time or a number of requests you choose, it analyses every PHP request on your site in depth and tells you how much time each plugin, each SQL query, each PHP function and each call to external servers has taken. With that, you know exactly where the problem is.

Create a trace

  1. In cPanel, open X-Ray App.

  2. At the top right, click Start tracing.

  3. Choose the domain you want to analyse.

  4. In Specify mask, enter which addresses to analyse:

    • A specific page: for dominio.com/direccion-lenta, enter direccion-lenta.
    • The home page: /.
    • All pages: *.
    • All pages that start with a path: for dominio.com/clientes/acceso, dominio.com/clientes/comprar, etc., enter clientes/*.

    You can also use ? and []; the form's How to use special characters? link explains how.

    Form for creating a trace in X-Ray

  5. By default X-Ray analyses a small number of requests that match the pattern. To analyse more requests or for longer, click Advanced settings and adjust it.

  6. Click Run.

The trace appears in the list. X-Ray does not generate visits: it waits for someone to load the pages. If it is a page with few visits, open it yourself in the browser a few times. When it reaches the set number of requests or time, it stops on its own; you can also stop it earlier.

List of running traces in X-Ray

If the page you want to analyse is served from cache (for example, from LiteSpeed Cache), PHP does not run and X-Ray records nothing. Analyse the page while logged in to WordPress or purge its cache first.

Read the results

You can wait for it to finish or look at the requests it has already analysed as it goes. They appear in a list you can sort by execution time, with the slow ones flagged first.

List of requests analysed by X-Ray sorted by time

When you open a request you will see:

  • The total execution time.
  • The exact URL.
  • The site's plugins or components and the time each one has taken.
  • Calls to external servers and how long they took.
  • SQL queries, with the file they come from and their time.
  • The PHP functions that take the most time and where they are in the code.

Time breakdown by plugin, SQL queries and functions in an X-Ray report

You can download the report as a PDF to send to the developer of the site or plugin.

Some typical cases:

  • One plugin takes most of the time: deactivate it and check whether the page improves. Look for an alternative or update it.
  • An external call takes several seconds (an API, a licensing service, a feed): the site waits for that server on every visit. Review the plugin that makes it.
  • An SQL query takes a long time, or a fast query is repeated hundreds of times: it usually points to a table without an index or a badly written plugin. If it is wp_options, see the wp_options table and autoload data.

Things to bear in mind

  • X-Ray slows down the requests it analyses. Analyse few requests, for a short time, and stop the trace once you have the information.

  • If the account is reaching its CPU or memory limits, the times are distorted. X-Ray flags this on the affected request so you can take it into account.

    X-Ray warning about a request affected by resource limits

  • X-Ray measures what happens on the server. The time the browser takes to download images or run JavaScript can be seen in PageSpeed Insights.

  • The report may include your site's URLs, queries and parameters. Review it before sharing it.

You may also find useful

Something wrong or out of date? Tell us and we will review it.