使用PHP的當前腳本確實有效,但顯然它需要很長時間,因爲有超過100萬的用戶名需要驗證。最快最有效的方法來運行一個循環來查找和驗證超過100萬用戶名關閉不同的網站?
這將檢查外部網站API並返回<span class="user">{userID}</span>
如果它是有效的用戶名,並且返回<span class="user">0</span>
如果不是。
$query = $db->query('SELECT id, username FROM users_to_verify'); // Over 1 million.
foreach($query as $row) {
$userID = $row['id'];
$userName = $row['username'];
if(!preg_match("/<span class=\"user\">0<\/span>/", file_get_contents("http://website.net/api.php?userName=".$userName)))
$db->query('UPDATE users_to_verify SET verified = 1 WHERE id = $userID');
}
}
這是最快的方法嗎?我也嘗試過使用cURL,但file_get_contents和cURL似乎都具有相同的性能,我也知道其中的一些將依賴於外部網站的響應時間,但我想確保我的方面使用最快,最好的辦法可能。
瓶頸將是遠程站點的響應時間。捲曲或替代品之間的差異可以忽略不計。確保遠程站點沒有速率限制,他們可能扼殺甚至阻止你。 – jszobody
調查multi_curl,可能會爲你節省一些時間 – Mihai
1,000,000次'preg_match()'的迭代肯定會減慢你的速度。你應該做'if(file_get_contents(「http://website.net/api.php?userName=」。$ userName)!===' 0')'而不是 – MonkeyZeus