php 如何获得先前使用 curl_setopt() 设置的选项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5356075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get an option previously set with curl_setopt()?
提问by hakre
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?
我只是想知道因为没有 curl_getopt() 函数,如何才能找出curl_setopt()
以前为特定选项设置的值?
采纳答案by leek
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.
问题:有没有办法获取当前的 curl 选项设置?像 curl_getopt() 或 curl_showopts()?
回答:是和否。有 curl_getinfo()会向您显示有关上次连接的一些信息,但我怀疑这不是您要查找的信息。恕我直言,这是卷曲的弱点。
My suggestion (and others) is to encapsulate cURL into a class where your $cURL->setOpt()
function also stores the value for retrieval later.
我的建议(和其他建议)是将 cURL 封装到一个类中,您的$cURL->setOpt()
函数还存储该值以供稍后检索。
The multirequestPHP library has this functionality (and then some!):
多请求PHP 库有这个功能(还有一些!):
$request = new \MultiRequest\Request($url);
$request->setCurlOption(CURLOPT_PROXY, $proxy);
// ...
$curlOptions = $request->getCurlOptions();
list($proxyIp, $proxyPort) = explode(':', $curlOptions[CURLOPT_PROXY]);
回答by Dr McKay
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.
或许curl_getinfo()
可以满足你的一些需求。如果没有,您可以编写一个包装器curl_setopt()
,将所有选项保存到一个数组中。