3

I am trying to find the value of the HTTP protocol that curl is using in a particular PHP application. I haven't been able to find a documented default for this.

Following a code snippet from this useful stackoverflow post (default-curl-option-values) I was able to print out the values of the curl options just before doing the curl_exec.

The result was CURLOPT_HTTP_VERSION = 84. However the three constants that we can use to set this are:

CURL_HTTP_VERSION_NONE = 0
CURL_HTTP_VERSION_1_0 = 1
CURL_HTTP_VERSION_1_1 = 2

Therefore the question is: What does a value of 84 imply? I am not seeing how the above constants can translate to 84 in some kind of bit combination? I could try this posted alternate way of seeing what curl is doing but I am still curious about how to read the option value.

Community
  • 1
  • 1
lolcode
  • 275
  • 4
  • 17
  • `84` is probably an index or offset in an cURL-internal data structure. And the correct answer to "how do I read a cURL-internal variable/setting?" is "you don't.". – Sammitch Sep 19 '13 at 20:07

1 Answers1

5

CURL_HTTP_VERSION isn't a variable you set, it's a parameter you supply to curl_setopt() to tell it which option you're setting. So 84 is just the number of this option, and its value is meaningless (except to the internals of curl_setopt().

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks, I guess I was mixed up about the constants for the option names vs. their values. I was able to use the snippet in this post to see the whole request including the protocol: http://stackoverflow.com/a/4406238/1331768 – lolcode Sep 19 '13 at 20:29
  • Any ideas why after setting CURLOPT_HTTP_VERSION to 3 (which means HTTP2) the request is still sent as HTTP/1.1? I have PHP 5.6. – andreszs Aug 03 '17 at 17:02
  • @Andrew As far as I can tell, the only valid values of `CURLOPT_HTTP_VERSION` are the values of the constants `CURL_HTTP_VERSION_NONE`, `CURL_HTTP_VERSION_1_0`, and `CURL_HTTP_VERSION_1_1`. Where did you learn that you can set it to `3`? – Barmar Aug 03 '17 at 18:26
  • The CURL_HTTP_VERSION_2_0 constant was added in libcurl 7.33: https://curl.haxx.se/libcurl/c/CURLOPT_HTTP_VERSION.html. Its internal value is 3, as I've seen in some examples around here. – andreszs Aug 03 '17 at 21:58
  • But does PHP use that version of libcurl? – Barmar Aug 03 '17 at 21:59