cURL is a friendly tool used by many programmers and DevOps around the world. Sometimes there is a need to measure how long our request takes, and how long we wait for the server to respond. In this article, we show how to present timing details with curl.
-w,--write-out <format> parameter
cURL offers formatted output for the request details. We will focus on details related to time.
- 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 connection 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, pretransfer, and transfer before the final transaction was started. time_redirect shows 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.
- time_total The total time, in seconds, that the full operation lasted.
To display time information to the standard output first we need to:
1) Create a new file, time-details.txt, and paste in:
2) Next, make a request using this file in the
-w parameter with
on Windows use:
What this command will do:
-w "@time-details.txt"- tells cURL to use our format file,
-o /dev/null- redirects the output of the request to
-s- tells cURL not to display a progress meter,
"http://google.com/"- is the URL we are requesting.
The output after we run that command:
3. cURL with time details wrapper
We could use a bash script that will work as a curl wrapper returning timing information.
1) First, create a curlt file
2) Paste the following content to the file
3) Make file executable
4) Make a request
In this article, we presented how to do a curl request with timing information.