Prodigal Son Posted November 23, 2008 Share Posted November 23, 2008 Does anyone know how I would go about doing this. I want to check if a certain website is down and if it is, I will display a message and if not display the default message. So is there a function where I can do something like this: if (website_down('http://www.example.com/')){ echo 'Example website is down'; } else { echo 'Example website is up'; } Quote Link to comment https://forums.phpfreaks.com/topic/133914-display-a-message-if-website-is-down/ Share on other sites More sharing options...
Prodigal Son Posted November 23, 2008 Author Share Posted November 23, 2008 Oops I posted this in the wrong section by mistake . Maybe a mod can move it to phphelp? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/133914-display-a-message-if-website-is-down/#findComment-697282 Share on other sites More sharing options...
phil88 Posted November 24, 2008 Share Posted November 24, 2008 The website_down function would need to try and contact the server and wait for an amount of time to see if the request times out - that could probably be done with a simple ping request. There isn't a function built into PHP that'll ping a server, but you might be able to use PHP's exec() function to call the server OS's ping program. Eg; <? $str=exec("ping -c 1 -w 1 ".$ip,$a,$a1); if(strlen($str)>1){ //website's up }else{ //website's down } ?> Completely untested of course. I started muddling together some code, then I found this so just posted the code I found on that page here. Should do what you want. Quote Link to comment https://forums.phpfreaks.com/topic/133914-display-a-message-if-website-is-down/#findComment-697301 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.