PHP経由でsocks5サーバーの速度を測定したいので、次のコードを書きました:
$url = 'http://cachefly.cachefly.net/1mb.test';
$proxy = '126.XXX.XXX.XXX:1080’;
//$auth = $username.':'.$password;
$fp = fopen('1mb.test', 'w');
$start = microtime(true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $auth);
$result = curl_exec($ch);
curl_close($ch);
$end = microtime(true);
fclose($fp);
$diff = $end - $start;
echo "elapsed time: ".$diff." seconds";
$a = 1024 / $diff;
echo '<br>'.floor($a).' kb/s';
残念ながら、コードは機能していません。Socks5 サーバーを使用しないと、ファイルは完全にダウンロードされます。コードが機能しない理由を知っている人はいますか? 目標を達成する方法について、代替案や提案はありますか?
よろしくお願いします。