JDMallion Posted September 24, 2007 Share Posted September 24, 2007 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!! Quote Link to comment https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/ Share on other sites More sharing options...
rarebit Posted September 24, 2007 Share Posted September 24, 2007 On each server have a page that just outputs it's name and the time on one line, and log it... If there's no response, then it's down and log you can log that... I'd use wget to do the call... Quote Link to comment https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/#findComment-353942 Share on other sites More sharing options...
HuggieBear Posted September 24, 2007 Share Posted September 24, 2007 I think I'd use the cURL library for this one, or maybe sockets as they'll probably give you better control over your requests. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/#findComment-353944 Share on other sites More sharing options...
d.shankar Posted September 24, 2007 Share Posted September 24, 2007 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/#findComment-353948 Share on other sites More sharing options...
JDMallion Posted September 24, 2007 Author Share Posted September 24, 2007 Thanks loads guys!! Very much appreciated! God I love these forums! Quote Link to comment https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/#findComment-353950 Share on other sites More sharing options...
d.shankar Posted September 24, 2007 Share Posted September 24, 2007 Did the code help or do you need someother help ? Quote Link to comment https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/#findComment-353951 Share on other sites More sharing options...
JDMallion Posted September 24, 2007 Author Share Posted September 24, 2007 Pretty sure that will do want I want it to mate, will just have to check we have Curl installed on the server! Or does it come with the standard PHP install? Quote Link to comment https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/#findComment-353974 Share on other sites More sharing options...
d.shankar Posted September 25, 2007 Share Posted September 25, 2007 No JD you have to install curl package. Download the latest php from here http://www.php.net/downloads.php#v5 To install cURL ..check this link http://www.php.net/manual/en/ref.curl.php Hope this could help. Quote Link to comment https://forums.phpfreaks.com/topic/70450-solved-website-checker-script/#findComment-354634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.