Run PHP file when external file is updated

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] $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,@msg.telus.com",$subject,$message,"From: SOWX ALERTS");
	 
	 }[/php]

What about storing the last warning in a variable and let the cron job run and get its data comapre with what is in the stored variable if it hasn’t changed don’t send an email and it it has then send the email.

That would be awesome, where would you recommend to start?

I managed to create a script that stores the time of creation of the bulletin in a .txt file. Now what I need to do is run the script once each time that the time is changed to a newer value. Any ideas on how I could do this?

Thanks, Dave

I would create a text file that stores two time stamps. One being the time the file was last updated, the other being the time the last message was sent. If the modified time is greater than the last sent time then the message would be sent again. Does that make sense?

Thanks for the help. Manage to figure out a better method. Using the email pipe method now.

Sponsor our Newsletter | Privacy Policy | Terms of Service