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

}

?>

Edited by davefootball123
Link to comment
Share on other sites

If you have sufficient access to install software on this system you could use incron instead of a regular cron daemon.

 

incron runs tasks based on filesystem events. This allows you to execute a script when a file changes for instance.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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