如何获得先前使用 curl_setopt() 设置的选项? [英] How to get an option previously set with curl_setopt()?
问题描述
我只是想知道因为没有 curl_getopt() 函数,如何才能通过 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?
推荐答案
摘自互联网上的各种答案:
Pulled from various answers around the internets:
问题:有没有办法获得当前卷曲选项设置?像一个curl_getopt() 还是 curl_showopts()?
Question: Is there a way to get the current curl option settings? Like a curl_getopt() or curl_showopts()?
答案:是和否.有curl_getinfo() 会告诉你一些关于上次连接的信息,但我怀疑这不是你要找的为了.恕我直言,这是卷曲的弱点.
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.
我的建议(和其他建议)是将 cURL 封装到一个类中,其中您的 $cURL->setOpt()
函数也存储该值以供稍后检索.
My suggestion (and others) is to encapsulate cURL into a class where your $cURL->setOpt()
function also stores the value for retrieval later.
multirequest PHP 库具有此功能(还有一些!):
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]);
这篇关于如何获得先前使用 curl_setopt() 设置的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!