What a flow of symbols.
is not even accepted by the system php the error at the same time
Be detailed please.
What error, where, at which line.
Provide screenshots, copy-paste error messages. Provide a full code you're trying to run.
Then we (and I) can help you.
Added.
I've just tested your code, your api is fine, you just use the wrong address - function directly says to you (in error message), that such a host can't be found, means, there's no such host in the Web at all.
Well, and I do agree, it's a very strange behavior for a function - instead of throwing an exception or returning some meaningful result, such as error-code, etc, it's just terminates your program execution with an error, well, yep, it's weird.
Possible solution, to prevent crashing of your program, may be like this:
Code: Select all
$host = "yui.psobbserv.net";
if(gethostbyname("yui.psobbserv.net")==$host) {
echo 'No such host in the Web';
}
else {
//checkOnlineStatus(); //your function that checks if server is up
}
Hope this helps.
Also, if you want to test a specific port of the host you're trying to connect to, you can use following code (or like-derivatives):
Code: Select all
function pingDomain($domain){
$starttime = microtime(true);
$file = fsockopen ($domain, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file) $status = -1; // Site is down
else {
fclose($file);
$status = ($stoptime - $starttime) * 1000;
$status = floor($status);
}
return $status;
}