当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::sendRequests方法代码示例

本文整理汇总了PHP中GuzzleHttp\Client::sendRequests方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::sendRequests方法的具体用法?PHP Client::sendRequests怎么用?PHP Client::sendRequests使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Client的用法示例。


在下文中一共展示了Client::sendRequests方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: next

 public function next()
 {
     if (count($this->responseCache) == 0) {
         $urls = $this->pageContainer->pop($this->parallelReqeusts);
         if (empty($urls)) {
             return false;
         }
         $requests = array();
         foreach ($urls as $url) {
             if (!$this->isFiltered($url)) {
                 $request = RequestFactory::getRequest($url, 'GET', 'php://memory', [], []);
                 $requests[] = $request;
             }
         }
         if (empty($requests)) {
             return $this->next();
         }
         try {
             $this->responseCache = $this->httpClient->sendRequests($requests);
         } catch (MultiHttpAdapterException $e) {
             $exceptions = $e->getExceptions();
             $errorMessages = "";
             foreach ($exceptions as $exception) {
                 // @fixme this must be part of the http client
                 $message = $exception->getMessage();
                 if (strpos($message, "An error occurred when fetching the URI") === 0) {
                     $url = substr($message, "41", strpos($message, '"', 41) - 41);
                     if (strpos($url, '/') === 0) {
                         $this->pageContainer->push(new Uri($this->startUri->getScheme() . '://' . $this->startUri->getHost() . $url));
                     }
                 } else {
                     $errorMessages .= $exception->getMessage() . "\n";
                 }
             }
             if ($errorMessages != "") {
                 throw new \RuntimeException($errorMessages);
             }
         }
     }
     if (empty($this->responseCache)) {
         return $this->next();
     }
     $response = array_pop($this->responseCache);
     if ($response->hasHeader('Content-Type')) {
         $contentTypeElements = explode(';', $response->getHeader('Content-Type')[0]);
         $contentType = array_shift($contentTypeElements);
         if ($contentType === "text/html") {
             $document = new Document((string) $response->getBody(), true);
             $elements = $document->getUnorderedDependencies($response->getUri());
             foreach ($elements as $element) {
                 $urlString = $this->createCleanUriString($element);
                 if (!array_key_exists($urlString, $this->comingFrom)) {
                     $this->comingFrom[$urlString] = $response->getUri();
                 }
                 $this->pageContainer->push($element);
             }
         }
     }
     return $response;
 }
开发者ID:phmlabs,项目名称:crawler,代码行数:60,代码来源:Crawler.php


注:本文中的GuzzleHttp\Client::sendRequests方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。