Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MCurl
- {
- protected $_urls;
- protected $_result;
- protected $_timeout;
- public function __construct($timeout = 5, $urls = false)
- {
- $this->_timeout = $timeout;
- $this->_urls = $urls ? $urls : array();
- $this->_result = array();
- }
- public function setTimeout($timeout)
- {
- $this->_timeout = $timeout;
- }
- public function setUrls($urls)
- {
- $this->_urls = $urls;
- }
- public function getResults()
- {
- if(!$this->_result) $this->scan();
- return $this->_result;
- }
- public function scan()
- {
- $curl = array();
- $mh = curl_multi_init();
- foreach ($this->_urls as $id => $url)
- {
- $url = trim($url);
- $curl[$url] = curl_init();
- curl_setopt($curl[$url], CURLOPT_URL, $url);
- curl_setopt($curl[$url], CURLOPT_USERAGENT, $us_agent);
- curl_setopt($curl[$url], CURLOPT_HEADER, 0);
- curl_setopt($curl[$url], CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl[$url], CURLOPT_TIMEOUT, $this->timeout);
- curl_multi_add_handle($mh, $curl[$url]);
- }
- $running = null;
- do curl_multi_exec($mh, $running);
- while($running > 0);
- foreach($curl as $url => $c)
- {
- $this->_result[$url] = curl_multi_getcontent($c);
- curl_multi_remove_handle($mh, $c);
- }
- curl_multi_close($mh);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement