前提:運行在命令行模式中(沒有超時設置)
多次調用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); ?> hope it helps ;)