<?php
$host = 'http://google.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
?>
I'm using the above program to get the status of site. But I always get an offline message. Is there any mistake with the code?
All you need to do is follow the steps below for a quick check: Visit Website Planet. Enter the URL of your website address on the field and press the Check button. Website Planet will show whether your website is online or not.
When looking at a graph, the domain is all the values of the graph from left to right. The range is all the values of the graph from down to up.
The isSiteAvailible() function performs a cURL request with PHP and checks if the domain is available and online. Return TRUE if the specified website is available, otherwise, return FALSE if the website is offline. Uses: Call the isSiteAvailible() function and pass the website URL that you want to check.
The hostname does not contain http://
, that is only the scheme for an URI.
Remove it and try this:
<?php
$host = 'google.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With