Make a cron job in server and run this code every 1 minute, then save the result in database. your live web site can load the servers status from database quickly, also use ajax to avoid from page refreshing.
i'm doing a script but i have an issue with page loading
Question
I'm doing a website(in php) that shows if a game server is online or offline.
I've managed to figure something out and got it to work.
But the problem is if multiple servers are offline, the website takes 10-20 seconds to load.
Loads instantly if servers are online.
Is there a way i can make the website load instantly even if the servers are offline?
this is the main function.(the rest are ip's and server names.)
function pingDomain($domain){
global $sport, $lport, $port, $l1, $l2;
if ($domain == $l1){
$port = $lport;
}
else if ($domain == $l2){
$port = $lport;
}
else{
$port = $sport;
}
$starttime = microtime(true);
$file = @fsockopen($domain, $port, $errno, $errstr, 1);
$stoptime = microtime(true);
$status = 0;
if (!$file) $status = -1; // Site is down
else {
fclose($file);
$status = ($stoptime - $starttime) * 1000;
$status = floor($status);
}
return $status;
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow