當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Varien_Http_Adapter_Curl::multiRequest方法代碼示例

本文整理匯總了PHP中Varien_Http_Adapter_Curl::multiRequest方法的典型用法代碼示例。如果您正苦於以下問題:PHP Varien_Http_Adapter_Curl::multiRequest方法的具體用法?PHP Varien_Http_Adapter_Curl::multiRequest怎麽用?PHP Varien_Http_Adapter_Curl::multiRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Varien_Http_Adapter_Curl的用法示例。


在下文中一共展示了Varien_Http_Adapter_Curl::multiRequest方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _executeRequests

 /**
  * Prepares and executes requests by given request_paths values
  *
  * @param array $info
  * @param Varien_Http_Adapter_Curl $adapter
  */
 protected function _executeRequests(array $info, Varien_Http_Adapter_Curl $adapter)
 {
     $storeId = $info['store_id'];
     $options = array(CURLOPT_USERAGENT => self::USER_AGENT, CURLOPT_SSL_VERIFYPEER => 0);
     $threads = $this->_getCrawlerThreads($storeId);
     if (!$threads) {
         $threads = 1;
     }
     if (!empty($info['cookie'])) {
         $options[CURLOPT_COOKIE] = $info['cookie'];
     }
     $urls = array();
     $offset = 0;
     Mage::getSingleton('core/session')->setCrawlerOffset($offset);
     while ($rewrites = $this->_getResource()->getRequestPaths($storeId)) {
         foreach ($rewrites as $rewriteRow) {
             $url = $this->_getUrlByRewriteRow($rewriteRow, $info['base_url'], $storeId);
             $urls[] = $url;
             if (count($urls) == $threads) {
                 $adapter->multiRequest($urls, $options);
                 $urls = array();
             }
         }
         $offset += self::BATCH_SIZE;
         Mage::getSingleton('core/session')->setCrawlerOffset($offset);
     }
     if (!empty($urls)) {
         $adapter->multiRequest($urls, $options);
     }
 }
開發者ID:xiaoguizhidao,項目名稱:magento,代碼行數:36,代碼來源:Crawler.php

示例2: requestUrls

 public function requestUrls($urls, $verbose = true)
 {
     $adapter = new Varien_Http_Adapter_Curl();
     $options = array(CURLOPT_USERAGENT => self::USER_AGENT, CURLOPT_HEADER => true);
     $multiResult = $adapter->multiRequest($urls, $options);
     foreach ($multiResult as $urlId => $content) {
         $urlModel = Mage::getModel('fpc/crawler_url')->load($urlId);
         $this->_removeDublicates($urlModel);
         $matches = array();
         preg_match('/Fpc-Cache-Id: (' . Mirasvit_Fpc_Model_Processor::REQUEST_ID_PREFIX . '[a-z0-9]{32})/', $content, $matches);
         if (count($matches) == 2) {
             $cacheId = $matches[1];
             if ($urlModel->getCacheId() != $cacheId) {
                 $urlModel->setCacheId($cacheId)->save();
             }
             if ($verbose) {
                 echo 'CACHED ' . $urls[$urlId] . PHP_EOL;
             }
         } else {
             if ($verbose) {
                 echo 'REMOVED ' . $urls[$urlId] . PHP_EOL;
             }
             $urlModel->delete();
         }
     }
     return $this;
 }
開發者ID:vinayshuklasourcefuse,項目名稱:sareez,代碼行數:27,代碼來源:Mirasvit_Fpc_Model_Crawler_Crawl.php

示例3: crawl

 public function crawl()
 {
     return $this;
     Mage::register('custom_entry_point', true, true);
     $counter = 0;
     $timeStart = time();
     $storesInfo = $this->getStoresInfo();
     $adapter = new Varien_Http_Adapter_Curl();
     foreach ($storesInfo as $info) {
         $options = array(CURLOPT_USERAGENT => self::USER_AGENT);
         $storeId = $info['store_id'];
         $threads = 1;
         if (!empty($info['cookie'])) {
             $options[CURLOPT_COOKIE] = $info['cookie'];
         }
         $urls = array();
         $urlsCount = 0;
         $totalCount = 0;
         $queries = Mage::getModel('catalogsearch/query')->getCollection()->addFieldToFilter('store_id', $storeId)->setOrder('popularity', 'desc');
         foreach ($queries as $query) {
             $queryText = $query->getQueryText();
             $part = '';
             for ($i = 0; $i < strlen($queryText); $i++) {
                 $part .= $queryText[$i];
                 $url = $info['base_url'] . 'searchautocomplete/ajax/get/?q=' . $part . '&cat=0';
                 $urls[] = $url;
                 $urlsCount++;
                 $totalCount++;
                 $counter++;
                 if ($urlsCount == $threads) {
                     $result = $adapter->multiRequest($urls, $options);
                     $urlsCount = 0;
                     $urls = array();
                 }
             }
             if (time() - $timeStart > 1 * 60 * 60) {
                 return $this;
             }
         }
         if (!empty($urls)) {
             $adapter->multiRequest($urls, $options);
         }
     }
     return $this;
 }
開發者ID:vinayshuklasourcefuse,項目名稱:sareez,代碼行數:45,代碼來源:Crawler.php

示例4: crawl

 /**
  * Crawl all system urls
  * @return Enterprise_PageCache_Model_Crawler
  */
 public function crawl()
 {
     $storesInfo = $this->getStoresInfo();
     $adapter = new Varien_Http_Adapter_Curl();
     foreach ($storesInfo as $info) {
         $options = array(CURLOPT_USERAGENT => self::USER_AGENT);
         $storeId = $info['store_id'];
         if (!Mage::app()->getStore($storeId)->getConfig(self::XML_PATH_CRAWLER_ENABLED)) {
             continue;
         }
         $threads = (int) Mage::app()->getStore($storeId)->getConfig(self::XML_PATH_CRAWLER_THREADS);
         if (!$threads) {
             $threads = 1;
         }
         $stmt = $this->_getResource()->getUrlStmt($storeId);
         $baseUrl = $info['base_url'];
         if (!empty($info['cookie'])) {
             $options[CURLOPT_COOKIE] = $info['cookie'];
         }
         $urls = array();
         $urlsCount = 0;
         $totalCount = 0;
         while ($row = $stmt->fetch()) {
             $urls[] = $baseUrl . $row['request_path'];
             $urlsCount++;
             $totalCount++;
             if ($urlsCount == $threads) {
                 $adapter->multiRequest($urls, $options);
                 $urlsCount = 0;
                 $urls = array();
             }
         }
         if (!empty($urls)) {
             $adapter->multiRequest($urls, $options);
         }
     }
     return $this;
 }
開發者ID:jpbender,項目名稱:mage_virtual,代碼行數:42,代碼來源:Crawler.php

示例5: _executeRequests

 /**
  * Prepares and executes requests by given request_paths values
  *
  * @param array $info
  * @param Varien_Http_Adapter_Curl $adapter
  */
 protected function _executeRequests(array $info, Varien_Http_Adapter_Curl $adapter)
 {
     $storeId = $info['store_id'];
     $options = array(CURLOPT_USERAGENT => self::USER_AGENT);
     $threads = $this->_getCrawlerThreads($storeId);
     if (!$threads) {
         $threads = 1;
     }
     if (!empty($info['cookie'])) {
         $options[CURLOPT_COOKIE] = $info['cookie'];
     }
     $urls = array();
     $urlsCount = $totalCount = 0;
     foreach ($this->_getResource()->getRequestPaths($storeId) as $requestPath) {
         $url = $info['base_url'] . $requestPath;
         $urlHash = md5($url);
         if (isset($this->_visitedUrls[$urlHash])) {
             continue;
         }
         $urls[] = $url;
         $this->_visitedUrls[$urlHash] = true;
         $urlsCount++;
         $totalCount++;
         if ($urlsCount == $threads) {
             $adapter->multiRequest($urls, $options);
             $urlsCount = 0;
             $urls = array();
         }
     }
     if (!empty($urls)) {
         $adapter->multiRequest($urls, $options);
     }
 }
開發者ID:booklein,項目名稱:bookle,代碼行數:39,代碼來源:Crawler.php

示例6: crawl

 /**
  * Crawl all system urls
  *
  * @return Enterprise_PageCache_Model_Crawler
  */
 public function crawl()
 {
     if (!Mage::app()->useCache('full_page')) {
         return $this;
     }
     $storesInfo = $this->getStoresInfo();
     $adapter = new Varien_Http_Adapter_Curl();
     foreach ($storesInfo as $info) {
         $options = array(CURLOPT_USERAGENT => self::USER_AGENT);
         $storeId = $info['store_id'];
         $this->_visitedUrls = array();
         if (!Mage::app()->getStore($storeId)->getConfig(self::XML_PATH_CRAWLER_ENABLED)) {
             continue;
         }
         $threads = (int) Mage::app()->getStore($storeId)->getConfig(self::XML_PATH_CRAWLER_THREADS);
         if (!$threads) {
             $threads = 1;
         }
         if (!empty($info['cookie'])) {
             $options[CURLOPT_COOKIE] = $info['cookie'];
         }
         $urls = array();
         $baseUrl = $info['base_url'];
         $urlsCount = $totalCount = 0;
         $urlsPaths = $this->_getResource()->getUrlsPaths($storeId);
         foreach ($urlsPaths as $urlPath) {
             $url = $baseUrl . $urlPath;
             $urlHash = md5($url);
             if (isset($this->_visitedUrls[$urlHash])) {
                 continue;
             }
             $urls[] = $url;
             $this->_visitedUrls[$urlHash] = true;
             $urlsCount++;
             $totalCount++;
             if ($urlsCount == $threads) {
                 $adapter->multiRequest($urls, $options);
                 $urlsCount = 0;
                 $urls = array();
             }
         }
         if (!empty($urls)) {
             $adapter->multiRequest($urls, $options);
         }
     }
     return $this;
 }
開發者ID:hazaeluz,項目名稱:magento_connect,代碼行數:52,代碼來源:Crawler.php


注:本文中的Varien_Http_Adapter_Curl::multiRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。