Jump to content

[SOLVED] Website Checker Script


JDMallion

Recommended Posts

Hi guys,

 

I want to write a PHP script to check several of the websites that we run. I will have it run each day using a CRON job therefore automatically checking our sites each morning.

 

I basically just want the script to go to each website and check that they are still up and running. Now I know that I will have to get the HTTP server response code to work out whether or not the website is up or not. But I am not 100% sure on how to do this!! A point in the right direction would be really good.

 

Thanks in advance for any help!!

Link to comment
Share on other sites

Yea use cURL.

 

I hope this is what you need.

 

<?php

$yoursites=array("www.google.com","www.yahoo.com","www.73645jgfsf.com"); //Enter your all websites here as shown.

for($i=0;$i<count($yoursites);$i++)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $yoursites[$i]);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_AUTOREFERER,false); 
$source = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if($httpCode==200)
{
echo $yoursites[$i]." is up.<br>";
}
else
{
echo $yoursites[$i]." is down.<br>";
}
curl_close($ch);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.