单次并发控制

在实际爬虫项目中, 我们往往要限制单次并发请求数量以防被服务器防火墙屏蔽, 而一个max_co参数就可以轻松地解决这个问题, max_co会将请求根据上限量分批将请求压入队列并执行收包.

  1. // max_co is the max number of concurrency request once, it's very useful to prevent server-waf limit.
  2. $requests = array_fill(0, 10, ['uri' => 'https://www.qq.com/']);
  3. echo SaberGM::requests($requests, ['max_co' => 5])->time."\n";
  4. echo SaberGM::requests($requests, ['max_co' => 1])->time."\n";