When troubleshooting website performance, it is often useful to measure how quickly a server responds to requests. If you have SSH access to a server, you can use the curl command-line tool to gather detailed timing information without relying on external testing services.
This method is useful for:
- Troubleshooting slow websites
- Measuring server response times
- Testing network connectivity
- Verifying performance after configuration changes
- Monitoring website availability
Table of Contents
What Is cURL?
cURL is a command-line tool used to transfer data using various protocols, including HTTP, HTTPS, FTP, and SMTP.
Besides downloading content, cURL can also display detailed information about a connection, including DNS lookup time, connection time, server response time, and total request duration.
Measuring Website Response Time
The following command displays several useful performance metrics for a website:
curl -o /dev/null -s -w "\
Server IP: %{remote_ip}\n\
DNS Lookup: %{time_namelookup} sec\n\
Connection Time: %{time_connect} sec\n\
TLS Handshake: %{time_appconnect} sec\n\
Time to First Byte: %{time_starttransfer} sec\n\
Total Time: %{time_total} sec\n" \
https://example.com
Replace https://example.com with the website you want to test.
Understanding the Results
Server IP
Displays the IP address of the server that responded to the request.
DNS Lookup
Shows how long it took to resolve the domain name into an IP address.
Connection Time
Measures the time required to establish a TCP connection to the server.
TLS Handshake
For HTTPS websites, this shows how long it took to establish the encrypted SSL/TLS connection.
Time to First Byte (TTFB)
One of the most important metrics.
It measures the time between sending the request and receiving the first byte of the response. A high TTFB often indicates:
- Slow application performance
- Database bottlenecks
- Overloaded servers
- Inefficient code
Total Time
The total duration of the request, including connection setup and content delivery.
Example Output
Server IP: 93.184.216.34
DNS Lookup: 0.005 sec
Connection Time: 0.030 sec
TLS Handshake: 0.065 sec
Time to First Byte: 0.120 sec
Total Time: 0.180 sec
Check Only the HTTP Status Code
If you only want to verify that a website is responding correctly:
curl -s -o /dev/null -w "%{http_code}\n" https://example.com
Example output:
200
Common status codes include:
200– OK301– Redirect404– Page not found500– Internal server error
Testing Multiple Times
To obtain more reliable results, run the test several times:
for i in {1..5}; do
curl -o /dev/null -s -w "Total Time: %{time_total} sec\n" https://example.com
done
This helps identify intermittent slowdowns and provides a more realistic view of website performance.
Summary
The curl utility is a simple but powerful tool for measuring website response times directly from the command line. By analyzing metrics such as DNS lookup time, connection time, Time to First Byte (TTFB), and total request duration, you can quickly identify potential performance bottlenecks and verify whether a website is responding as expected.