RSS 提要更新时运行 PHP 脚本(cron 作业?)
我有一个脚本,可以根据 PHP 文件中的内容向用户发送推送通知。 这就是那个文件……重要的部分……
$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();
这就是发送通知的 PHP。当 PHP 脚本加载时,它会发出通知。
它从提要中加载第一个帖子并将其发送出去。我想在每次 RSS 提要更新新帖子时发送通知。如果它更新为新的提要,那么我想运行上面的代码。
那么我该如何做到这一点并确保它经常运行呢?
我真的很想看看我需要检查哪些代码是否已更新?我不知道如何检查更新,但这可能是脚本中最重要的部分。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
配置 Cron 每隔 1 小时运行一次脚本,并在脚本中添加代码以检查 RSS 是否已修改。
编辑:
1. 您可以将 Cron 配置为每 1 小时运行一次脚本。
2. 在脚本中添加测试RSS是否被修改的代码。
3. 要检查 Feed 是否已更改,请使用标签。您可以将标签内容保存到txt中并进行比较。
4. 要编写标签内容,您可以使用 SimpleXML 和fwrite。
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.