duanhao1004 2012-11-26 11:43
浏览 118
已采纳

如何加速/分解多个部分的过程。 Rss,Curl,PHP

Im experimenting with some RSS reader/fetcher im writing at the moment. Everything is going smoothly except 1 thing. It's terribly slow.

Let me explain:

  1. I fetch the list of RSS feeds from the database
  2. I iterate every feed from this list, open it with cURL and parse it with SimpleXMLElement
  3. I check descriptions and title's of these feeds with a given keyword, to see if its already in database or not.
  4. If its not i add it to database.

For now i am looping through 11 feeds. Which gives me a page loading time of 18 seconds. This is without updating the database. When there are some new articles found, it goes up to 22 seconds (on localhost).

On a live webserver, my guess is that this will be even slower, and maybe goes beyond the limit php is setup to.

So my question is, what are your suggestions to improve speed.. and if this is not possible, whats the best way to break this down into multiples executions, like say 2 feeds at a time? I'd like to keep it all automated, dont want to click after every 2 feeds.

Hope you guys have some good suggestions for me!

If you want some code example let me know and ill paste some

Thanks!

  • 写回答

2条回答 默认 最新

  • dongliulu1122 2012-11-26 12:20
    关注

    I would suggest you use a cronjob or a daemon that automatically synchronizes the feeds with your database by running a php script. That would remove the delay from the user's perspective. Run it like every hour or whatever suits you.

    Though first, you should possibly try and figure out which parts of the process are actually slow. Without the code it's hard to tell what could be wrong.

    Possible issues could be:

    • The remote servers(which store the feeds) are slow
    • Your local server's internet connection
    • Your server's hardware
    • And obviously the code
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于php中URL传递GET全局变量的问题
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件