php curl 发送请求失败问题


前提:运行在命令行模式中(没有超时设置)

多次调用curl ,可能出现发送请求失败的问题, 原因可以是curl连接复用,使用的是缓存池中的建立。

解决方法:设置curl 参数,

curl_setopt($chCURLOPT_FORBID_REUSE1);
curl_setopt($chCURLOPT_FRESH_CONNECT1);

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

hope it helps ;)

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM