鍍金池/ 問答/PHP  Linux/ php curl post請求執(zhí)行一次curl_exce 請求的接口確執(zhí)行兩次

php curl post請求執(zhí)行一次curl_exce 請求的接口確執(zhí)行兩次

1、php curl post請求接口,打印日志執(zhí)行了一次curl_exce,但是請求的接口卻重復(fù)執(zhí)行兩次.
2、代碼:
$ch = curl_init();

if(false === $ch){
    writeRedisLog('create_curl', $activity_id, $mobile, $user_id, '', 0, 'curl failed to initialize');
}
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
writeLog($activity_id, $mobile, $user_id.'_H');
$res = curl_exec($ch);
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error_no = curl_errno($ch);
$error_str = curl_error($ch);
curl_close($ch);
//if(!$res){
    writeRedisLog('error_request', $activity_id, $mobile, $user_id, $res, $error_no, $error_str);
//}
//推送結(jié)果處理
$res = json_decode($res, true);

curl操作請求接口的日志:
_H===15515420703=2018-06-25 16:53:25=http://myhost.com/special/car... (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

在接口中打印的日志:

clipboard.png

有遇到這種情況的嗎

回答
編輯回答
喜歡你

遇到這種情況,我之前的問題是,加載圖片資源的路徑寫錯,導(dǎo)致每次點擊都發(fā)起了兩次請求

這種情況解決辦法:查看nginx、或者apache日志,看看到底發(fā)起了什么請求,或者看看firebug

2017年8月9日 20:45