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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器