![](/img/trans.png)
[英]PHP/HTML Getting the array multiple and storing into an array to sum them up
[英]Getting random urls from google and storing them into array
我需要檢查與某些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;
現在讓我說而不是'stackoverflow.com'網址,我想使用多個網址,例如以下數組列表:
$imones = array ("php.net","w3schools.com", "stackoverflow.com");
while (list(, $value) = each($imones)) {
$imoneslist = "$value<br />\n";
如何將$ imoneslist數組放入$ url1?
$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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.