コード例 #1
0
 public function run() : array
 {
     $success = [];
     $failed = [];
     $client = new Client(['timeout' => $this->timeout]);
     $pool = new Pool($client, $this->requests(), ['concurrency' => count($this->urls), 'fulfilled' => function (Response $response, string $url) use(&$success, &$failed) {
         if (false !== strpos((string) $response->getBody(), $this->needle)) {
             $success[] = $url;
         } else {
             $failed[] = $url;
         }
     }]);
     $pool->promise()->wait();
     $failed = array_merge($failed, array_diff($this->urls, $success, $failed));
     return [$success, $failed];
 }