Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 MultiRequestRequest($url);
$request->setCurlOption(CURLOPT_PROXY, $proxy);
// ...
$curlOptions = $request->getCurlOptions();
list($proxyIp, $proxyPort) = explode(':', $curlOptions[CURLOPT_PROXY]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...