【问题标题】:CURL return false only sometimesCURL 有时只返回 false
【发布时间】: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 秒 .. 结果相同

标签: php api curl


【解决方案1】:

此问题已由端点服务器的托管公司解决

  • 不是卷曲问题
  • 它是不是端点服务器的数据库引擎
  • 不是 SSL 问题

firewall 有时会阻止请求,希望以后可以帮助某人

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-18
    • 2011-04-05
    • 2021-05-12
    • 2013-07-03
    • 1970-01-01
    • 2016-06-08
    • 2014-01-23
    • 1970-01-01
    相关资源
    最近更新 更多