0

我正在开发一个解析推文并将它们保存到数据库的项目。我还想创建一个本地的前端界面,当推文进来时会实时更新(没有页面重新加载等)。我使用的是这里看到的基本 AJAX/PHP 轮询模型。但我需要的是:

当一条推文进入并被解析时,出于性能原因,我想将其写入一个 .txt 文件,可能只是他们的名称、句柄和推文。我想以 JSON 格式编写它。而且我需要 php 来监视该文件并在每次将新条目附加到文本文件时提取最后一个条目。这是正确的方法吗?有没有人这样做过?谢谢!

4

1 回答 1

0

The best way to do this would be a push model, as suggested. Node.js has made this alot simpler by just including socket.io and emitting the message, letting socket.io do the complex stuff (it does websockets as a first choice and last pick is the polling model you looked at, all depending on browser support). Just fetch the tweets, store it in the database and at the same time send it to your node application that will in turn emit it to all subscribers.

于 2012-08-13T17:10:03.383 回答