Jump to content

Check something, wait, check again, do something!


grunshaw

Recommended Posts

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

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!";
}
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.