某些选项未在php的curl_getinfo中填充

时间:2017-09-11 21:43:21

标签: php curl

我看到curl_getinfo的返回值中没有填充一些选项,最明显的是CURLINFO_LOCAL_IP。这是运行curl的代码:

    $ch = curl_init("http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
$m = fopen('php://memory', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $m);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
print_r(curl_getinfo($ch));
var_dump(curl_error($ch));
$p = ftell($m);
$p += 1 << 20;
rewind($m);
$stderr = fread($m, $p);
//var_dump($stderr);
fclose($m);
curl_close($ch);

(curl_error或stderr输出中没有任何注释)

这是curl_getinfo转储:

Array
(
    [url] => http://www.example.com/
    [content_type] => text/html
    [http_code] => 200
    [header_size] => 322
    [request_size] => 54
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.007369
    [namelookup_time] => 0.004603
    [connect_time] => 0.005864
    [pretransfer_time] => 0.005921
    [size_upload] => 0
    [size_download] => 1270
    [speed_download] => 172343
    [speed_upload] => 0
    [download_content_length] => 1270
    [upload_content_length] => 0
    [starttransfer_time] => 0.007324
    [redirect_time] => 0
    [redirect_url] =>
    [primary_ip] => XX.XX.XX.XXX // omitted for obvious reasons
    [certinfo] => Array
        (
        )

)

我也可以直接使用curl来填充local_ip宏:

$ curl -w '%{local_ip}' 'www.example.com'
...
XX.X.XXX.X // omitted, but I promise it's here

0 个答案:

没有答案