温馨提示  2024年 6月我们已经停止开发者板块文章内容更新,谢谢来访。存档数据
知识 2023-08-29 31 次阅读

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

   

php curl请求失败的解决方案 1. 打开相应的php文件; 2. 设置“curl,setopt($ch, curlopt,forbid,reuse, 1)...”即可。

本文操作环境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<?phpcurl,setopt($ch, curlopt,httpheader, array(content-type: text/xml));?>makesure you watch for cache issue:the below code will prevent cache...<?phpcurl,setopt($ch, curlopt,forbid,reuse, 1);curl,setopt($ch, curlopt,fresh,connect, 1);?>