RSS源更新时运行PHP脚本(cron作业?)

时间:2010-11-23 18:42:04

标签: php iphone rss cron apple-push-notifications

我有一个脚本,根据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脚本时发出通知。

它从Feed中加载第一个帖子并将其发送出去。我想在每次使用新帖子更新RSS源时发送通知。如果使用新的Feed更新,那么我想运行上面的代码。

那我怎么能这样做并确保它经常运行?

我真的很想看看我需要检查哪些代码更新?我不知道如何检查更新,这可能是脚本中最重要的部分。

1 个答案:

答案 0 :(得分:3)

将Cron配置为每次运行脚本1小时并在脚本中添加要检查的代码是RSS修改。

编辑:
1.您可以配置Cron来运行您的脚本,例如: 1小时 2.在脚本中添加代码以测试RSS是否已被修改 3.要检查Feed是否已更改,请使用标签。您可以将标记内容保存到txt并进行比较 4.要编写代码内容,您可以使用SimpleXMLfwrite