我有一个在线功能,需要连接到 PHP 数组中几个网站中最快的服务器。
这是我走了多远。我使用 Fopen 检查网站是否在线并使用 foreach 重定向到它。我认为最快的服务器会首先重定向,但它只是重定向了 URL 中数组中的最后一项。
这是我走了多远:
// The URLs to check in an Array.
$urls = ['website1.com', 'website2.com', 'website3.com'];
// Get the fastest server (the fastest server should redirect first)
foreach($urls as $proxy) {
if ($socket = @ fsockopen($proxy, 80, $errno, $errstr, 30)) {
header('Location: https://'.$proxy.'');
fclose($socket);
} else {}
}
echo 'Connecting to the fastest server...';
提前致谢。我期待看到你的回复:)