Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an option previously set with curl_setopt()?

Tags:

php

curl

I'm just wondering as there is no curl_getopt() function, how it is possible to find out which value has been set for a specific option with curl_setopt() previously?

like image 798
hakre Avatar asked Mar 18 '11 18:03

hakre


People also ask

What is Curl_setopt used for?

The curl_setopt() function will set options for a CURL session identified by the ch parameter. The option parameter is the option you want to set, and the value is the value of the option given by the option.

What is Curlopt_verbose?

When CURLOPT_VERBOSE is set, output is written to STDERR or the file specified using CURLOPT_STDERR . The output is very informative. You can also use tcpdump or wireshark to watch the network traffic.

What is Curlopt_postfields?

CURLOPT_POSTFIELDS. The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'.


2 Answers

Pulled from various answers around the internets:

Question: Is there a way to get the current curl option settings? Like a curl_getopt() or curl_showopts()?

Answer: Yes and no. There is curl_getinfo() which will show you some info about the last connection, but I suspect it's not what you're looking for. It's a weakness in curl, IMHO.

My suggestion (and others) is to encapsulate cURL into a class where your $cURL->setOpt() function also stores the value for retrieval later.

The multirequest PHP library has this functionality (and then some!):

$request = new \MultiRequest\Request($url); $request->setCurlOption(CURLOPT_PROXY, $proxy); // ... $curlOptions = $request->getCurlOptions(); list($proxyIp, $proxyPort) = explode(':', $curlOptions[CURLOPT_PROXY]); 
like image 198
leek Avatar answered Oct 02 '22 08:10

leek


Possibly curl_getinfo() may satisfy some of your needs. If not, you can write a wrapper of curl_setopt() which saves all options to an array.

like image 24
Dr McKay Avatar answered Oct 02 '22 07:10

Dr McKay