CURLINFO_PRETRANSFER_TIME_T(3)

πŸ’… CURLINFO_PRETRANSFER_TIME_T(3) πŸ’…

okay so bestie, welcome to the Library Functions Manual β€” yes that's the manual name, and yes we're gonna get into it. This one's all about CURLINFO_PRETRANSFER_TIME_T, and the header up top says it plain: time to transfer start. Periodt. πŸŽ€


✨ NAME ✨

CURLINFO_PRETRANSFER_TIME_T β€” literally the time it takes to get to transfer start, no cap.


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRETRANSFER_TIME_T,
                           curl_off_t *timep);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the vibe: you pass in a pointer to a curl_off_t, and it gets filled with the time β€” in microseconds β€” that it took from the start until the file transfer is just about to begin. Like, the moment right before things actually pop off. πŸ”₯

This timestamp is a whole package deal, iykyk. It includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved. It also includes the sending of the protocol-specific instructions that trigger a transfer. Basically all the behind-the-scenes main character prep work. πŸ’…

And when a redirect is followed? The time from each request is added together. Every single hop, all summed up. Not me keeping receipts on every redirect 😭

Also, definitely go peek at the TIMES overview in the curl_easy_getinfo(3) man page β€” it's giving essential reading. πŸ“š


🌈 PROTOCOLS 🌈

This functionality affects all supported protocols. Every single one. No gatekeeping. 🫢


⭐ EXAMPLE ⭐

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_off_t pretransfer;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
    result = curl_easy_perform(curl);
    if(CURLE_OK == result) {
      result = curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME_T,
                                 &pretransfer);
      if(CURLE_OK == result) {
        printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld\n",
               pretransfer / 1000000,
               (long)(pretransfer % 1000000));
      }
    }
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
}

look at that math splitting out the seconds and microseconds β€” she ate that ngl πŸ“


🧚 AVAILABILITY 🧚

Added in curl 7.61.0. So if you're on something older, that's a no from her, sorry bestie πŸ’€


πŸ’œ RETURN VALUE πŸ’œ

curl_easy_getinfo(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK πŸŽ‰ β€” non-zero means an error occurred, so go check libcurl-errors(3) to find out what went down. πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

(yes, this page links to itself, and honestly? iconic. self-referential queen. ⭐)


and that's the whole thing, bestie! πŸŽ€ this little beauty comes to you from libcurl, dated 2026-10-12 β€” go forth and time your pretransfers, mwah πŸ’‹πŸ¦‹

πŸ“¦ where this page comes from