本文操作环境:windows7系统,PHP7.1版,Dell G3电脑。如何解决php curl请求失败问题?php curl 发送请求失败问题前提:运行在命令行模式中(没有超时设置)多次调用curl ,可能出现发送请求失败的问题, 原因可
本文操作环境:windows7系统,PHP7.1版,Dell G3电脑。
如何解决php curl请求失败问题?
php curl 发送请求失败问题
前提:运行在命令行模式中(没有超时设置)
多次调用curl ,可能出现发送请求失败的问题, 原因可以是curl连接复用,使用的是缓存池中的建立。
解决方法:设置curl 参数,
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
参考链接:https://www.php.net/manual/zh/function.curl-setopt.php
例外一个参考case:
if you would like to send xml request to a server (lets say, making a soap proxy),
you have to set
<?php
curl_setopt($ch, CURLOPT_HttpHEADER, Array("Content-Type: text/xml"));
?>
makesure you watch for cache issue:
the below code will prevent cache...
<?php
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
?>
--结束END--
本文标题: 如何解决php curl请求失败问题
本文链接: https://www.lsjlt.com/news/954.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0