并发请求

注意: 此处使用了并发重定向优化方案, 多个重定向总是依旧并发的而不会退化为队列的单个请求

  1. $responses = SaberGM::requests([
  2. ['uri' => 'http://github.com/'],
  3. ['uri' => 'http://github.com/'],
  4. ['uri' => 'https://github.com/']
  5. ]);
  6. echo "multi-requests [ {$responses->success_num} ok, {$responses->error_num} error ]:\n" ."consuming-time: {$responses->time}s\n";
  7. // multi-requests [ 3 ok, 0 error ]:
  8. // consuming-time: 0.79090881347656s
  1. // 别名机制可以省略参数书写参数名
  2. $saber = Saber::create(['base_uri' => 'http://httpbin.org']);
  3. echo $saber->requests([
  4. ['get','/get'],
  5. ['post','/post'],
  6. ['patch','/patch'],
  7. ['put','/put'],
  8. ['delete','/delete']
  9. ]);