grunshaw Posted October 14, 2009 Share Posted October 14, 2009 Hi guys. I wonder if someone can help me with this. Basically, what I want to do is (for arguments sake I will use google.com as an example) check to see if google.com is alive. If its alive, I want it to stop and exit. If its not, I want it to wait a defined amount of time (say 30 seconds) and then check again. If its up this time, I want it to exit, however, if tis still down, I want it to do something (ie send an email). Any help would be much appriciated. Thanks James G Link to comment https://forums.phpfreaks.com/topic/177648-check-something-wait-check-again-do-something/ Share on other sites More sharing options...
jonsjava Posted October 14, 2009 Share Posted October 14, 2009 here's an example of what you want. Just FYI: most people won't respond if you don't have a working idea of what you want. <?php error_reporting(NULL); function pingDomain($domain){ $starttime = microtime(true); $file = fsockopen ($domain, 80, $errno, $errstr, 10); $stoptime = microtime(true); $status = 0; if (!$file){ return false; } // Site is down else { fclose($file); return true; } } $domain = "google.com"; if (!pingDomain($domain)){ echo "sleeping for 5...\n"; sleep(30); if (!pingDomain($domain)){ print "failed a 2nd time. giving up..."; //run some command } } else{ echo "success!"; } ?> Link to comment https://forums.phpfreaks.com/topic/177648-check-something-wait-check-again-do-something/#findComment-936949 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.