How HTTP client-server interaction works
A Web server receives a request from a client for index.php page, for example, generates a page with static HTML content and sends to the client. This is Time to First byte (TTFB).
Then client web browser starts executing index.php: requests content mentioned in the page – various scripts, images etc. The scripts are delivered from the server and web browser starts executing them.
Possible causes
- Server-side problems: web or MySQL service workload/bad optimisation.
- Network problems: connection is not stable or bandwidth is not sufficient.
- Site uses not optimal PHP version
- Website code problems: content size and website code optimisation.
- Slow DNS servers are used.
Troubleshooting steps
1. Web server
Note: To get an idea what is a good value, compare your website performance against big service providers such as Google, Youtube, Amazon, Microsoft, etc.
Check Time To First Byte (TTFB) value for static (e.g. .html files) and dynamic (e.g. .php files) content:
# curl -s -w ‘nLookup time:tt%{time_namelookup}nConnect time:tt%{time_connect}nSSL handshake time:t%{time_appconnect}nPre-Transfer time:t%{time_pretransfer}nRedirect time:tt%{time_redirect}nStart transfer time:t%{time_starttransfer}nnTotal time:tt%{time_total}n’ -o /dev/null http://example.com
Lookup time: 0.055
Connect time: 0.224
SSL handshake time: 0.000
Pre-Transfer time: 0.225
Redirect time: 0.000
Start Transfer time: 0.395
Total time: 0.395
Subtract the “Start Transfer” value from the “Pre-Transfer” value to get TTFB value. In the example above, the TTFB value is a lot less than 1 second and this means that the web server is not causing the issue. If the value is more than one second, follow the steps from this article to troubleshoot the web server further: TTFB is too high. Another reason can be due to exceeded FcgidMaxProcesses processes or reached pm.max_children PHP-FPM limit. Also, basic checking for possible DDoS attack can be performed.
2. PHP version
Plugins, Themes periodically are updated and require higher PHP version. Switch PHP to highest possible version in Domains > example.com > Hosting Settings
3. MySQL server
The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimisation. Activate MySQL slow query log and make sure that there are no entries. Contact website developer if slow queries are found. The article: MySQL performance is slow. How to improve it? – can help to investigate MySQL performance issue.
4. Network connection
Try to open the website from a workstation in the other physical location (webpagetest.org or tools.pingdom.com). If from the other location/network it opens fine, contact system administrator to test network connection bandwidth (iperf) and stability (mtr). If the bandwidth is small, consider compressing website static content (images) – see the next step.
If most of bandwidth is taken by DNS, test website with another DNS servers, for example use 8.8.8.8 Google DNS.
5. Website content
-
If the website is “heavy”, optimize its size by compressing images, for example.
-
Use…