Jump to content

Run PHP file when external file is updated


davefootball123

Recommended Posts

I coded a PHP script that sends a text message to a list of people who are subscribed when severe weather warnings are issued. The script works good. However the problem right now is if I have it on a cron job every 5 minutes to check for a warning, every 5 minutes that a warning is in effect a text message will be sent to the subscribers. Is there a way to have a 5 minutes cron job but only send the text if the external file at the weather service is updated? That probably sounds really complicated but I will include my simple part of the text message script. Thanks for the help, Dave

 


<?PHP
//SUBJECT AND BODY OF EMAIL SHOULD BE LESS THAN 160 CHARACTERS TOTAL
$url = 'http://www.weatheroffice.gc.ca/rss/warning/on-151_e.xml';
$search_torwarn = 'SNOW SQUALL WARNING IN EFFECT';
$subject = "SOWX ALERT";
$message = "Snow Squall Warning For: Barrie - Collingwood - Hillsdale. Visit http://www.sowx.ca for more information. ";

$file_contents = file_get_contents($url);


if(strpos($file_contents, $search_torwarn) !== FALSE){

mail("@msg.telus.com,[email protected]",$subject,$message,"From: SOWX ALERTS");

}

?>

I managed to get the creation time/update time of the bulletin and but it in a text file. That works good. Considering I only need it for the one file the next step may be easy. How can I have the script look at the text file with the time of the bulletin and have it only run the text script if the bulletin is new? Any Ideas or help would be greatly appreciated.

 

 

Thanks, Dave

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.