PHP cURL IPv6连接时间在第一次请求时非常慢


PHP cURL IPv6 connect_time very slow on first request

我正在尝试制作一个PHP脚本,该脚本生成并向eth0分配一个随机IPv6地址,并执行HTTP请求,但似乎所有地址都需要通过首先发出一个伪请求来"初始化"。但是,我需要IP在创建后的一秒钟内为HTTP请求做好准备。经过数小时的测试和互联网搜索,我找不出问题,所以我来到了这里。

我的Debian VPS有一个/64 IPv6地址空间分配给它。

为了解释这个问题,我这样做了:

首先,我手动分配9个IP

ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:1 dev eth0 valid_lft 600 preferred_lft 600                       
ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:2 dev eth0 valid_lft 600 preferred_lft 600                       
ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:3 dev eth0 valid_lft 600 preferred_lft 600                       
ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:4 dev eth0 valid_lft 600 preferred_lft 600                       
ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:5 dev eth0 valid_lft 600 preferred_lft 600                       
ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:6 dev eth0 valid_lft 600 preferred_lft 600                       
ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:7 dev eth0 valid_lft 600 preferred_lft 600                       
ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:8 dev eth0 valid_lft 600 preferred_lft 600                       
ip addr change 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:9 dev eth0 valid_lft 600 preferred_lft 600                       

PHP脚本:

<?php
$URL = "ipv6.whatismyv6.com";
for($i=1; $i<10; $i++)
{
    $ch = curl_init();
    $IP = "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:{$i}";
    curl_setopt($ch, CURLOPT_URL, $URL);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
    // Set IPv6
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
    curl_setopt($ch, CURLOPT_INTERFACE, $IP);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    print "IP {$IP}'n";
    curl_exec($ch);
    if(curl_errno($ch))
        die(curl_error($ch));
    var_dump(curl_getinfo($ch));
    print "'nDone for IP {$IP}'n'n";
    curl_close($ch);
}

在第一次运行脚本时,我得到了这个输出。正如您所看到的,除了第一个请求外,每个请求的connect_time都是32秒。看起来cURL在尝试连接之前需要花费30秒的时间。

IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:1
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(2.041753)
  ["namelookup_time"]=>
  float(0.969251)
  ["connect_time"]=>
  float(2.002953)
  ["pretransfer_time"]=>
  float(2.002985)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(708)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(2.04171)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:1"
  ["local_port"]=>
  int(46353)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:1
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:2
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(32.02449)
  ["namelookup_time"]=>
  float(3.1E-5)
  ["connect_time"]=>
  float(31.986268)
  ["pretransfer_time"]=>
  float(31.986298)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(45)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(32.024464)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:2"
  ["local_port"]=>
  int(53907)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:2
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:3
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(32.080273)
  ["namelookup_time"]=>
  float(1.9E-5)
  ["connect_time"]=>
  float(32.041328)
  ["pretransfer_time"]=>
  float(32.041358)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(45)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(32.080247)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:3"
  ["local_port"]=>
  int(56910)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:3
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:4
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(32.124284)
  ["namelookup_time"]=>
  float(1.9E-5)
  ["connect_time"]=>
  float(32.085118)
  ["pretransfer_time"]=>
  float(32.085152)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(45)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(32.124239)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:4"
  ["local_port"]=>
  int(59346)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:4
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:5
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(32.074903)
  ["namelookup_time"]=>
  float(1.6E-5)
  ["connect_time"]=>
  float(32.036185)
  ["pretransfer_time"]=>
  float(32.036232)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(45)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(32.074879)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:5"
  ["local_port"]=>
  int(50604)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:5
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:6
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(32.425055)
  ["namelookup_time"]=>
  float(0.35623)
  ["connect_time"]=>
  float(32.386056)
  ["pretransfer_time"]=>
  float(32.386088)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(44)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(32.425031)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:6"
  ["local_port"]=>
  int(35632)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:6
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:7
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(35.150028)
  ["namelookup_time"]=>
  float(2.0E-5)
  ["connect_time"]=>
  float(35.111304)
  ["pretransfer_time"]=>
  float(35.111331)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(41)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(35.149998)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:7"
  ["local_port"]=>
  int(54827)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:7
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:8
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(32.09912)
  ["namelookup_time"]=>
  float(2.0E-5)
  ["connect_time"]=>
  float(32.06125)
  ["pretransfer_time"]=>
  float(32.061287)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(45)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(32.099082)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:8"
  ["local_port"]=>
  int(45077)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:8
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:9
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(32.050919)
  ["namelookup_time"]=>
  float(2.4E-5)
  ["connect_time"]=>
  float(32.011934)
  ["pretransfer_time"]=>
  float(32.01196)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(45)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(32.050894)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:9"
  ["local_port"]=>
  int(48069)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:9

我在第一次运行完成后立即运行了脚本,这就是这次的输出。现在connect_time都很好,我希望在第一次请求时也是这样。

IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:1
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(1.00357)
  ["namelookup_time"]=>
  float(0.93072)
  ["connect_time"]=>
  float(0.966039)
  ["pretransfer_time"]=>
  float(0.966092)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(1440)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(1.003512)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:1"
  ["local_port"]=>
  int(42623)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:1
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:2
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.074783)
  ["namelookup_time"]=>
  float(1.6E-5)
  ["connect_time"]=>
  float(0.035955)
  ["pretransfer_time"]=>
  float(0.035979)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(19335)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(0.07476)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:2"
  ["local_port"]=>
  int(60928)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:2
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:3
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.076524)
  ["namelookup_time"]=>
  float(2.2E-5)
  ["connect_time"]=>
  float(0.03672)
  ["pretransfer_time"]=>
  float(0.036757)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(18896)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(0.076497)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:3"
  ["local_port"]=>
  int(37292)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:3
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:4
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.074629)
  ["namelookup_time"]=>
  float(2.1E-5)
  ["connect_time"]=>
  float(0.035955)
  ["pretransfer_time"]=>
  float(0.036001)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(19375)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(0.074593)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:4"
  ["local_port"]=>
  int(53553)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:4
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:5
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.074592)
  ["namelookup_time"]=>
  float(2.0E-5)
  ["connect_time"]=>
  float(0.036058)
  ["pretransfer_time"]=>
  float(0.036093)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(19385)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(0.074564)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:5"
  ["local_port"]=>
  int(51041)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:5
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:6
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.074324)
  ["namelookup_time"]=>
  float(1.9E-5)
  ["connect_time"]=>
  float(0.035745)
  ["pretransfer_time"]=>
  float(0.035784)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(19455)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(0.074282)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:6"
  ["local_port"]=>
  int(37542)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:6
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:7
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.07241)
  ["namelookup_time"]=>
  float(2.3E-5)
  ["connect_time"]=>
  float(0.035187)
  ["pretransfer_time"]=>
  float(0.035246)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(19969)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(0.072382)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:7"
  ["local_port"]=>
  int(50575)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:7
IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:8
array(27) {
  ["url"]=>
  string(26) "HTTP://ipv6.whatismyv6.com"
  ["content_type"]=>
  string(9) "text/html"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(174)
  ["request_size"]=>
  int(58)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.074898)
  ["namelookup_time"]=>
  float(2.1E-5)
  ["connect_time"]=>
  float(0.036041)
  ["pretransfer_time"]=>
  float(0.036079)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(1446)
  ["speed_download"]=>
  float(19306)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(1446)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(0.074861)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["primary_ip"]=>
  string(14) "2001:4810::110"
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(33) "2001:19f0:xxxx:xxxx:xxxx:xxxx:2:8"
  ["local_port"]=>
  int(58766)
  ["redirect_url"]=>
  string(0) ""
  ["request_header"]=>
  string(58) "GET / HTTP/1.1
Host: ipv6.whatismyv6.com
Accept: */*
"
}
Done for IP 2001:19f0:xxxx:xxxx:xxxx:xxxx:2:8

此外,

wget --bind-address=2001:19f0:xxxx:xxxx:xxxx:xxxx:3:1 http://ipv6.whatismyv6.com

与PHP脚本中的第一个请求一样,工作得很好。

我已经和这个问题斗争了好几天了,所以我们非常感谢您的帮助。

添加IPv6地址后,系统通常会进行重复地址检测(DAD),以确保没有其他系统使用相同的地址。这可能需要几秒钟的时间。如果你真的需要能够立即使用地址,你需要在接口上禁用DAD:

echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_dad