卷曲连接失败

curl failed to connect

我尝试使用 curl 从同一台服务器上安装的 piwik 获取数据。我得到这个错误。

Failed to connect to example.com port 80: Connection refused

我的卷曲看起来像这样:

    $url = 'http://example.com/index.php?module=API&method=VisitsSummary.getVisits&idSite=1&
nb_uniq_visitors&period=month&date=today&token_auth=blabla';

    $ch = curl_init();
    $timeout = 30; // set to zero for no timeout
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $file_contents = curl_exec($ch);

    print_r (curl_error($ch));
    curl_close($ch);



    // display file
    print_r ($file_contents);

有人知道如何解决这个问题吗? 我关闭了 iptables。

尝试添加:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

1. 检查您的 allow_url_fopen 是否启用:

echo ini_get('allow_url_fopen');

ini_set('allow_url_fopen', 1);

2. 如果您可以 shell 访问您的服务器,请使用本地命令(wget、w3m、lynx、curl 命令)打开 URL , 远程登录, ...):

wget http://www.example.com
telnet www.example.com 80

3. 尝试打开与另一个 PHP 函数的连接:

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
  echo "$errstr ($errno)<br />\n";
} else {
  $out = "GET / HTTP/1.1\r\n";
  $out .= "Host: www.example.com\r\n";
  $out .= "Connection: Close\r\n\r\n";
  fwrite($fp, $out);
  while (!feof($fp)) {
    echo fgets($fp, 128);
  }
  fclose($fp);
}

4. 用 IP 替换主机名:

$url = 'http://210.220.112.2/index.php?module=API&method=VisitsSummary.getVisits&idSite=1&
nb_uniq_visitors&period=month&date=today&token_auth=blabla';