douniang3866 2013-02-04 22:10
浏览 374

执行大量http请求(HEAD)的最快方法是什么? [重复]

Possible Duplicate:
Asynchronous HTTP requests in PHP

I have a script that uses a foreach loop and takes an item id from a file and checks a head request if the status is 200. It is going to take a long time for this script to run, so is there any way I can do multiple requests at one time? I know with ajax if i do a for loop with $.ajax() it will start them all at once. how can I get this behavior with php or is there an alternative to allow for batch processing?

  • 写回答

3条回答 默认 最新

  • duanqin9631 2013-02-04 22:16
    关注

    A single request is easy (like you note). Justloop through and Use the Pear library HTTP_Request2 and make a HEAD request:

      $request = new HTTP_Request2('http://www.your_url.com/',
                             HTTP_Request2::METHOD_HEAD);
      $response = $request->send();
      if (200 == $response->getStatus()) {
        echo "Yippie... a 200";
      } 
    

    You can also use the php curl library, but it's much more futz to deal with: Header only retrieval in php via curl

    However, to do it in soley PHP in parallel you'd need to do use something like an exec() to fork off other php scripts as PHP does not support threaded programming or concurrency natively. Similarly, you could also use some kind of custom job/worker queue using gearman or something, but that's pretty involved.

    评论

报告相同问题?

悬赏问题

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