請求業務方B接口時,返回了報錯信息
My NOTICE [請求接口失敗信息]
請求接口URL:http://xxxx.com/xx/xx
請求接口時間:30.026
請求接口返回狀態:200
請求接口錯誤信息:connect() timed out!
請求接口錯誤碼:28
請求接口發送的參數:Arrayphp
本地模擬請求,若是是寫一個不存在的域名xx.com,會報錯html
Could not resolve host:
隨手寫了一個ip地址,報錯就成了redis
Connection timed out after 2000 milliseconds
因爲沒法判斷誰來背鍋,並且正式環境沒法復現。只能採起重試的方法。
簡單邏輯以下curl
<?php $ch = curl_init(); // curl_setopt ($ch, CURLOPT_URL, 'produc_redis.php.com'); curl_setopt ($ch, CURLOPT_URL, '11.11.11.1'); // I changed UA here curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt ($ch, CURLOPT_AUTOREFERER, true); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 2); $html = curl_exec($ch); var_dump($html,curl_error($ch)); $num=3; for($i=1;$i<=$num;$i++){ if(curl_getinfo($ch,CURLINFO_HTTP_CODE)=='0' && $i<=$num){ echo "retry $i 次".PHP_EOL; if($i==3){ curl_setopt ($ch, CURLOPT_URL, '220.181.57.217'); } $html = curl_exec($ch); } } var_dump($html); var_dump(curl_error($ch)); // var_dump(curl_getinfo($ch));
bool(false) string(44) "Connection timed out after 2000 milliseconds" retry 1 次 retry 2 次 retry 3 次 string(81) "<html> <meta http-equiv="refresh" content="0;url=http://www.baidu.com/"> </html> " string(0) "" [Finished in 6.1s]