Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the site status - up or down

Tags:

php

web

<?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?

like image 351
joHN Avatar asked Mar 22 '12 05:03

joHN


People also ask

How do you check if the site is down?

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.

Is domain up and down?

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.

How can I tell if a site is down in PHP?

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.


1 Answers

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.';
}
?>
like image 145
stewe Avatar answered Oct 12 '22 22:10

stewe