Peter Kern aka nomagic

nomagic.net

Mostly traveling between developer needs, cloud platforms and bug hunts. Team Player. Jack of all trades (aka T-shaped cloud engineer with focus on architecture)

Measuring HTTP Communication with Curl

Curl can do a lot for you. It supports more than 20 differnt protocols and so it is not surprising that every now and then I discover a new feature.

Peter Kern

2-Minute Read

Logo of cURL

Measuring HTTP Communication with Curl 1

curl is a sweet little “command line tool and library for transferring data with URLs”.

I mostly use curl for a quick test of http/https services. Occasionally I use it also for smtp or ldap services.

But curl can do a lot more for you. It supports more than 20 differnt protocols and so it is not surprising that every now and then I discover a new feature.

Today, while debugging a bottleneck in a http communication, I learned about the -w (or --write-out) flag of curl.

With this flag you can print out a lot of variables after a data transfer has completed.

curl -w "Status Code: %{response_code}\n" https://nomagic.net

The command above will write out the status code of GET-Request to the given URL.

To see the different timing aspects of the underlying http communication you can use the following variables:

  • %{time_appconnect} the time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed
  • %{time_connect} the time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed
  • %{time_namelookup} the time, in seconds, it took from the start until the name resolving was completed
  • %{time_pretransfer} the time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved
  • %{time_redirect} the time, in seconds, it took for all redirection steps including name lookup, connect, pre-transfer and transfer before the final transaction was started. time_redirect the complete execution time for multiple redirections
  • %{time_starttransfer} the time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result (aka TTFB or Time to first byte)
  • %{time_total} the total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution
curl -w "Connect/Handshake: %{time_appconnect}\nTCP Connect: %{time_connect}\n
DNS Lookup: %{time_namelookup}\nPretransfer: %{time_pretransfer}\nRedirect: %{time_redirect}\n
TTFB: %{time_starttransfer}\nTotal: %{time_total}" -o /dev/null https://nomagic.net

Connect/Handshake: 0.055654
TCP Connect: 0.018375
DNS Lookup: 0.007056
Pretransfer: 0.055793
Redirect: 0.000000
TTFB: 0.076804
Total: 0.076924

If you want to learn more about the magic of curl I would recommend a look at the book Everything curl. It is available online and for free.

Happy curling!


  1. Image “curl logo” is from https://curl.se/logo/curl-logo.jpg ↩︎

comments powered by Disqus

Recent Posts

Categories

About

Unicorns ... invite them to your release party but do not expect them to do your work.

Datenschutz