예제 #1
0
 public function performAction()
 {
     $rollingCurl = new RollingCurl();
     foreach ($this->getPerlTablesUrlList() as $url) {
         $rollingCurl->get($url);
     }
     $rollingCurl->setCallback(function (Request $request, RollingCurl $rollingCurl) {
         $this->response->addContent($request->getUrl());
         $content = $request->getResponseText();
         $this->parsePerlTable($content);
     })->execute();
 }
예제 #2
0
 /**
  * Prepares a passed in data array with img elements that need to be fetched from remote server and changed to point to a local resource.
  *
  * @param DOMDocument $doc 	The DOMDocument to evaluate img elements for
  * @param \RollingCurl\RollingCurl $rollingCurl 		The RollingCurl instance to add our requests to
  * @param string $tempDirPath   The directory to store images
  * @param array $imgData 	The data array to populate
  */
 private function prepareImageRequests($doc, $rollingCurl, $tempDirPath, $imgData)
 {
     global $wgServer;
     // Ensure there's a trailing slash after our $wgServer name
     if (substr($wgServer, -1) !== '/') {
         $search = $wgServer .= '/';
     } else {
         $search = $wgServer;
     }
     $imgElements = $doc->getElementsByTagName('img');
     foreach ($imgElements as $imgElement) {
         $src = $imgElement->getAttribute('src');
         // Strip the server and slash from our image src
         $localPath = str_replace($search, '', $src);
         $pathInfo = pathinfo($localPath);
         // Create the directory locally to mimic the directory structure of the server
         $localPath = $tempDirPath . '/' . $pathInfo['dirname'];
         if (!is_dir($localPath)) {
             $result = mkdir($localPath, 0777, true);
             if (!$result) {
                 throw new Exception("Failed to create temp directory: {$localPath}");
             }
         }
         $localPath = $localPath .= '/' . $pathInfo['basename'];
         $zipPath = $pathInfo['dirname'] . '/' . $pathInfo['basename'];
         $request = new \RollingCurl\Request($src);
         $imgData[] = array('src' => $src, 'element' => $imgElement, 'extension' => $pathInfo['extension'], 'local_path' => $localPath, 'new_path' => $zipPath, 'request' => $request);
         $rollingCurl->add($request);
     }
 }
예제 #3
0
 /**
  * Sends rolling curl multirequest.
  * @param array $data curl request data as [url, url, ...] or [url=>['post'=>[...], 'files'=>[...]]]
  * @param \Closure $callback callback at response.
  */
 public function multiRequest($data, $callback)
 {
     $rollingCurl = new RollingCurl();
     foreach ($data as $url => $options) {
         if (is_string($options)) {
             $url = $options;
         }
         if ($this->unique && in_array($url, $this->visited) && !@$options['post']) {
             continue;
         } else {
             $this->visited[] = $url;
         }
         $method = isset($options['post']) ? 'POST' : 'GET';
         $request = new Request($url, $method);
         $curlOptions = $this->getCurlOptions($url, @$options['post'], @$options['files']);
         $request->setOptions($curlOptions);
         $rollingCurl->add($request);
     }
     $rollingCurl->setCallback($callback)->execute();
 }