Run a PHP script when RSS feed updates (cron jobs?)
I have a script that sends out a push notification to users based on whats in a PHP file. This is that file ...the parts that matter ...
$doc = new DOMDocument();
$doc->load('RandomXML Url location here ');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
);
array_push($arrFeeds, $itemRSS);
}
// APPLE APNS EXAMPLE 1
$apns->newMessage(2);
$apns->addMessageAlert($itemRSS['title']);
// $apns->addMessageCustom('acme2', array('bang', 'whiz'));
$apns->queueMessage();
// SEND ALL MESSAGES NOW
$apns->processQueue();开发者_开发问答
So thats the PHP that sends out the notification. It sends out the notification when this PHP script is loaded.
It loads the first post from the feed and sends it out. I want to send a notification out every time the RSS feed is updated with a new post. If it is updated with a new feed, then I want to run the above code.
So how can I do that and make sure it is run frequently?
I would really like to see what code I need to check if its updated? I don't know how to check for updates though and thats probably the most important part of the script.
Configure Cron to run your script every e.g. 1 hour and in script add code to check is RSS modified.
EDIT:
1. You can configure Cron to run your script every e.g. 1 hour.
2. To the script, add the code to test whether the RSS has been modified.
3. To check whether the feed was changed use the tag. You can save the tag content to txt and compare it.
4. To write tag content you can use SimpleXML and fwrite.
精彩评论