Check the status of a page

By: Jool
Check the status of a page using php


Sometimes it is useful to know whether a certain website is online or if it is down. This could be part of a more complex script, so even just a simple status page. Either way, the principle is the same. Using the fsockopen() function we can check to see what’s up and what isn’t, quite easily too.

<?
$status = @fsockopen("www.jooldesigns.net", 80, $errno, $errstr, 30);
if($status)
{
echo "JoolDesigns appear to be online!";
}
else
{
echo "JoolDesigns appear to be offline at this time.";
}
?>


What we are doing here is using the fsockopen() function, checking the url (Note: do not use http:// in front of the url!!) and then echoing it’s status at the end. This is quite simple, like I said before it can be used as part of a large script, for example if I wanted to connect to another site for whatever reason using php, I’d want to know that it is online before I started. That is just an example, there are many uses both simple and complicated for this handy piece of code.