Advertisement
Guest User

Untitled

a guest
May 19th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <?php
  2. class MCurl
  3. {
  4.     protected $_urls;
  5.     protected $_result;
  6.     protected $_timeout;
  7.    
  8.     public function __construct($timeout = 5, $urls = false)
  9.     {
  10.         $this->_timeout = $timeout;
  11.         $this->_urls = $urls ? $urls : array();
  12.         $this->_result = array();
  13.     }
  14.    
  15.     public function setTimeout($timeout)
  16.     {
  17.         $this->_timeout = $timeout;
  18.     }
  19.        
  20.     public function setUrls($urls)
  21.     {
  22.         $this->_urls = $urls;  
  23.     }
  24.    
  25.     public function getResults()
  26.     {
  27.         if(!$this->_result) $this->scan();
  28.         return $this->_result;
  29.     }
  30.    
  31.     public function scan()  
  32.     {
  33.         $curl = array();  
  34.         $mh = curl_multi_init();
  35.         foreach ($this->_urls as $id => $url)
  36.         {
  37.             $url = trim($url);
  38.             $curl[$url] = curl_init();
  39.             curl_setopt($curl[$url], CURLOPT_URL, $url);
  40.             curl_setopt($curl[$url], CURLOPT_USERAGENT, $us_agent);
  41.             curl_setopt($curl[$url], CURLOPT_HEADER, 0);
  42.             curl_setopt($curl[$url], CURLOPT_RETURNTRANSFER, 1);
  43.             curl_setopt($curl[$url], CURLOPT_TIMEOUT, $this->timeout);
  44.             curl_multi_add_handle($mh, $curl[$url]);
  45.         }
  46.  
  47.         $running = null;
  48.         do curl_multi_exec($mh, $running);
  49.         while($running > 0);
  50.  
  51.         foreach($curl as $url => $c)
  52.         {
  53.             $this->_result[$url] = curl_multi_getcontent($c);
  54.             curl_multi_remove_handle($mh, $c);
  55.         }
  56.        
  57.         curl_multi_close($mh);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement