douwen7905 2015-09-11 15:56
浏览 155

使用http请求进行PHP后台同步

I have a php coded that is suppose to sync data from thousands of http links every 2 minutes and update the database.

However, some of the websites are too slow, and my current approach which is using foreach and going over the links one by one takes around 15 minutes.

Is there a better way to achieve this task in a shorter time?

foreach($email as $emails) {

imap_open(......);

// update db

}

Thanks

  • 写回答

2条回答 默认 最新

  • draj840143 2015-09-11 16:13
    关注

    Without sample code it's difficult to advise. However it may be that you are using a connection method which 'blocks' until the response is received. This means PHP stops until that request has completed one at a time.

    What you need is to connect to multiple systems at once and poll for responses.

    fsockopen() can do this, if you set stream_set_blocking() on the socket before writing the http request headers. Then fread can

    An alternate solution would be to fork the PHP into many processes each requesting a different source.

    Is that enough to point you in the right direction? If not please include some sample code so we know what methods you currently use and somebody may expand it to do what you require.

    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应