-1

我需要检查到某个 url 的连接时间,我使用curl进行操作(当时我只知道如何为 1 个 url 执行此操作,我的问题是我需要检查许多 url,而不仅仅是 1 个)

这是我如何计算连接时间的示例:

$url1 = 'stackoverflow.com';
$curl1 = curl_init();
curl_setopt($curl1, CURLOPT_URL, $url1);
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($curl1);
$contime1 = curl_getinfo($curl1, CURLINFO_CONNECT_TIME);
echo $contime1;

现在让我们说我想使用多个 url 而不是 'stackoverflow.com' url,例如这个数组列表:

$imones = array ("php.net","w3schools.com", "stackoverflow.com");
while (list(, $value) = each($imones)) {
$imoneslist = "$value<br />\n";

如何将 $imoneslist 数组放入 $url1?

4

1 回答 1

2
$imones = array ("php.net","w3schools.com", "stackoverflow.com");
foreach($imones as $url1) {
    $curl1 = curl_init();
    curl_setopt($curl1, CURLOPT_URL, $url1);
    curl_setopt($curl1, CURLOPT_RETURNTRANSFER, TRUE);
    curl_exec($curl1);
    $contime1 = curl_getinfo($curl1, CURLINFO_CONNECT_TIME);
    echo $url1 . ' took ' . $contime1 . ' seconds to connect<br />';
}

经测试。样本结果:

php.net took 0.032 seconds to connect 
w3schools.com took 0.124 seconds to connect 
stackoverflow.com took 0.016 seconds to connect
于 2013-02-12T17:37:35.827 回答