6

私の VPS サーバーの php ファイルでこのコードを検討してください。

<?php $url = 'http://www.google.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3)     Gecko/20041001 Firefox/0.10.1" );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
$ci = curl_getinfo($ch);
curl_close($ch);
var_dump($ci); ?>

これを返します

array(22) { 
["url"]=> string(21) "http://www.google.com" 
["content_type"]=> string(24) "text/html; charset=UTF-8" 
["http_code"]=> int(200) 
["header_size"]=> int(2055) 
["request_size"]=> int(147) 
["filetime"]=> int(-1) 
["ssl_verify_result"]=> int(0) 
["redirect_count"]=> int(0) 
["total_time"]=> float(50.095466) 
["namelookup_time"]=> float(0.001114) 
["connect_time"]=> float(50.019724) 
["pretransfer_time"]=> float(50.019825) 
["size_upload"]=> float(0) 
["size_download"]=> float(23156) 
["speed_download"]=> float(462) 
["speed_upload"]=> float(0) 
["download_content_length"]=> float(-1) 
["upload_content_length"]=> float(0) 
["starttransfer_time"]=> float(50.070702) 
["redirect_time"]=> float(0) 
["certinfo"]=> array(0) { } 
["redirect_url"]=> string(0) 
"" }

1 日に数回テストした後、「connect_time」は一貫して 50 秒をマークしています。1 秒以下でなくても、10 倍速くなるはずです。

私はサーバー構成に詳しくありませんが、サーバーの CPU または RAM に問題がある可能性があると言われました。top コマンドラインを使用して、次のように表示しましたが、これは問題ないようです。

タスク: 合計 80、実行中 1、睡眠 79、停止 0、ゾンビ 0

CPU: 0.0%us、0.0%sy、0.0%ni、100.0%id、0.0%wa、0.0%hi、0.0%si、0.0%st

メモリ: 合計 2097152k、使用済み 1273128k、空き 824024k、バッファ 0k

スワップ: 合計 0k、使用済み 0k、空き 0k、キャッシュ 0k

この問題の原因は何でしょうか?

編集:追加情報

ping www.google.com の結果。どこまでも続きそうだったので、195行目でコマンドを止めました

PING www.l.google.com (74.125.224.178) 56(84) バイトのデータ。

lax02s01-in-f18.1e100.net (74.125.224.178) からの 64 バイト: icmp_seq=1 ttl=56 time=12.0 ms

lax02s01-in-f18.1e100.net (74.125.224.178) からの 64 バイト: icmp_seq=2 ttl=56 time=12.1 ms

lax02s01-in-f18.1e100.net (74.125.224.178) からの 64 バイト: icmp_seq=3 ttl=56 time=11.9 ms

...

lax02s01-in-f18.1e100.net (74.125.224.178) からの 64 バイト: icmp_seq=194 ttl=56 time=11.9 ms

lax02s01-in-f18.1e100.net (74.125.224.178) からの 64 バイト: icmp_seq=195 ttl=56 time=11.9 ms

--- www.l.google.com ping 統計 --- 195 パケット送信、194 受信、0% パケット損失、時間 194711ms

traceroute wwww.google.com の結果

www.google.com (74.125.224.180) への traceroute、最大 30 ホップ、60 バイト パケット

1 ip- - -*- .ip.secureserver.net ( .*. . ) 0.585 ミリ秒 0.642 ミリ秒 0.778 ミリ秒

2 be10.trmd0215-01.ars.mgmt.phx3.gdg (208.109.112.126) 0.599 ミリ秒 0.777 ミリ秒 0.893 ミリ秒

3 ip-97-74-253-122.ip.secureserver.net (97.74.253.122) 11.840 ミリ秒 12.119 ミリ秒 12.275 ミリ秒

4 ip-97-74-253-122.ip.secureserver.net (97.74.253.122) 12.389 ミリ秒 12.482 ミリ秒 12.600 ミリ秒

5 PR01.LAX03.google.com (206.223.123.21) 11.739 ミリ秒 11.709 ミリ秒 11.707 ミリ秒

6 209.85.248.185 (209.85.248.185) 11.986 ミリ秒 11.797 ミリ秒 11.781 ミリ秒

7 72.14.236.11 (72.14.236.11) 12.606 ミリ秒 12.363 ミリ秒 12.328 ミリ秒

8 lax02s01-in-f20.1e100.net (74.125.224.180) 11.774 ミリ秒 11.864 ミリ秒 11.842 ミリ秒

4

2 に答える 2

18

試す:

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); 

上記は、cURL が最初に IPv6 を試行するのを防ぎます。

于 2012-06-21T20:47:04.007 に答える
0

私はあなたが与えたのと同じ構成を実行し、次のようになりました:

array
  'url' => string 'http://www.google.com' (length=21)
  'content_type' => string 'text/html; charset=UTF-8' (length=24)
  'http_code' => int 200
  'header_size' => int 2079
  'request_size' => int 151
  'filetime' => int -1
  'ssl_verify_result' => int 0
  'redirect_count' => int 0
  'total_time' => float 0.281
  'namelookup_time' => float 0
  'connect_time' => float 0
  'pretransfer_time' => float 0
  'size_upload' => float 0
  'size_download' => float 23168
  'speed_download' => float 82448
  'speed_upload' => float 0
  'download_content_length' => float -1
  'upload_content_length' => float 0
  'starttransfer_time' => float 0.187
  'redirect_time' => float 0
  'certinfo' => 
  array
    empty
  'redirect_url' => string '' (length=0)

私の推測では、サーバー接続自体に帯域幅の問題があるか、別のプロセスによって何らかの形で課税されている可能性があります。

于 2012-06-21T17:13:20.863 に答える