首页  >  文章  >  后端开发  >  如何解决php curl请求失败问题

如何解决php curl请求失败问题

藏色散人
藏色散人原创
2021-12-27 09:52:304747浏览

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);

参考链接: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);
?>

推荐学习:《PHP视频教程

以上是如何解决php curl请求失败问题的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn