怎么解决php curl请求失败问题

本篇内容介绍了“怎么解决php curl请求失败问题”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

php curl请求失败的解决办法:1、打开相应的PHP文件;2、设置“curl_setopt($ch, CURLOPT_FORBID_REUSE, 1)...”即可。

怎么解决php 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);

例外一个参考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);
?>

“怎么解决php curl请求失败问题”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!