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