【发布时间】:2018-10-19 12:50:57
【问题描述】:
我有两台服务器,一台提供带端点的 API,另一台通过 CURL 连接到第一个服务器
一切正常,但有时 curl 返回 false.. 如果我再试一次 .. 它再次工作。
你可以说如果我停止发送 curl 请求 2-3 分钟然后再返回 .. 第一个请求将在超时结束后返回 false .. 然后第二次尝试就可以了..
这真的很奇怪,,,你能建议我吗!
我的代码:
$params = array(
"type" => 'Get',
"get_param" => 'Installments',
"language" => 'tr',
"client_ip" => $_SERVER['REMOTE_ADDR']
);
$api_url = 'https://blabla/portal/web/api/v1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$response = curl_exec($ch);
echo '<pre>';
var_dump($response);
var_dump(curl_getinfo($ch));
var_dump(curl_errno($ch));
var_dump(curl_error($ch));
echo '</pre>';
回应
bool(false)
array(26) {
["url"]=>
string(52) "https://blabla/portal/web/api/v1"
["content_type"]=>
NULL
["http_code"]=>
int(0)
["header_size"]=>
int(0)
["request_size"]=>
int(0)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(60.001051)
["namelookup_time"]=>
float(0.004364)
["connect_time"]=>
float(0.006517)
["pretransfer_time"]=>
float(0)
["size_upload"]=>
float(0)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(-1)
["upload_content_length"]=>
float(-1)
["starttransfer_time"]=>
float(0)
["redirect_time"]=>
float(0)
["redirect_url"]=>
string(0) ""
["primary_ip"]=>
string(12) "82.222.47.39"
["certinfo"]=>
array(0) {
}
["primary_port"]=>
int(443)
["local_ip"]=>
string(13) "37.230.110.12"
["local_port"]=>
int(54335)
}
int(28)
string(71) "Operation timed out after 0 milliseconds with 0 out of 0 bytes received"
【问题讨论】:
-
这里增加时间看看:-
curl_setopt($ch, CURLOPT_TIMEOUT, 30); -
60 秒 .. 结果相同