/var/www/doncode.com.ua/www/obmen/include
NameSizeModeActions
jpgraph/-0775rm
config.php6870644editdlrm
doncode_multi_cURL.class.php81990644editdlrm
footer.php400644editdlrm
func.php191270644editdlrm
func_mysql.php49810644editdlrm
func_pars.php3770644editdlrm
header.php6610644editdlrm
smsclub.com.ua.class.php62520644editdlrm
Edit: /var/www/doncode.com.ua/www/obmen/include/doncode_multi_cURL.class.php (8199B)
$url) { $this->addUrl($url); } } $this->mh = curl_multi_init(); } public function setProxyList($ProxyList) { $this->ProxyList = $ProxyList; } public function getProxyList() { return $this->ProxyList; } public function getProxy() { if ((count($this->ProxyList) - 1) > $this->ProxyIndex) { $this->ProxyIndex++; } return trim($this->ProxyList[$this->ProxyIndex]); } public function haveProxy() { if (is_array($this->ProxyList) && count($this->ProxyList) > 0) { return true; } else { return false; } } public function countActiveThread() { return count($this->conn); } public function countWaitThread() { return count($this->urls); } public function getThread() { return $this->thread; } public function setThread($thread) { $this->thread = $thread; } public function addUrl($url) { if ($this->debug) { $this->log('addUrl('.$url.')'); } return $this->addUrlARR(array('url'=>$url)); } public function addUrlARR($arr) { $url = trim($arr['url']); if (!is_string($url) || $url == '') { return false; } $this->i++; $this->urls[$this->i] = $url; $this->urlsARR[$this->i] = $arr; return $this->i; } public function start() { foreach ($this->urls as $i => $url) { if (count($this->conn) >= $this->thread) { break; } $this->addThread($i); } $this->started = true; } private function default_curl_opt(){ $arr[CURLOPT_AUTOREFERER] = 1; $arr[CURLOPT_RETURNTRANSFER] = 1; $arr[CURLOPT_TIMEOUT] = $this->timeout; $arr[CURLOPT_USERAGENT] = $this->all_useragents[array_rand($this->all_useragents)]; if($this->haveProxy()){ $arr['CURLOPT_PROXY'] = $this->getProxy(); } return $arr; } protected function addThread($i) { $url = $this->urls[$i]; $this->conn[$i] = curl_init($url); $curl_opt = $this->default_curl_opt(); if(isset($this->urlsARR[$i]['curl']) && is_array($this->urlsARR[$i]['curl'])){ foreach ($this->urlsARR[$i]['curl'] as $key => $value) { $curl_opt[$key] = $value; } } //print_r($curl_opt); foreach ($curl_opt as $key => $value) { curl_setopt($this->conn[$i], $key, $value); } curl_multi_add_handle($this->mh, $this->conn[$i]); $this->work_urls[$i] = $this->urls[$i]; unset($this->urls[$i]); } protected function remove_handle($readyI) { curl_multi_remove_handle($this->mh, $this->conn[$readyI]); unset($this->conn[$readyI], $this->urls[$readyI]); $this->start(); } protected function getIDbyhandle($handle) { $readyI = false; foreach ($this->conn as $i => $con) { if ($this->conn[$i] == $handle) { $readyI = $i; break; } } return $readyI; } public function getReady() { //if (!$this->started) { $this->start(); //} $data = array(); $status = curl_multi_exec($this->mh, $this->active); $info = curl_multi_info_read($this->mh); while ($info) { if ($this->debug) { print_r($info); } //print_r($info); unset($i, $handle, $readyI); $readyI = $this->getIDbyhandle($info['handle']); if ($this->debug) { echo "readyI:$readyI\r\n"; } //var_dump($this->conn[$readyI]); //exit; if ($readyI !== false) { if ($this->debug) { echo("ready:$readyI active:{$this->active}\r\n"); } $status = curl_getinfo($this->conn[$readyI], CURLINFO_HTTP_CODE); if ($this->debug) { echo "status:$status\r\n"; } $data[$readyI] = curl_multi_getcontent($this->conn[$readyI]); //��������� �������� if ($status == 200) { //$data[$readyI] = curl_multi_getcontent($this->conn[$readyI]); // file_put_contents($filenames[$readyI], $data); } //вызов callback if(isset($this->urlsARR[$readyI]['onLoad'])){ if( is_object($this->urlsARR[$readyI]['onLoad']) && method_exists($this->urlsARR[$readyI]['onLoad'], 'onLoad') ){ $this->urlsARR[$readyI]['onLoad']->onLoad($data[$readyI], $status, $this->conn[$readyI]); } } $this->remove_handle($readyI); $info = curl_multi_info_read($this->mh); } } return $data; } public function doProcess(){ do { usleep(100000); $data = $this->getReady(); $countActiveThread = $this->countActiveThread(); $countWaitThread = $this->countWaitThread(); foreach($data as $key=>$val){ if ($this->debug) { $this->log('Exec ['.$key.'] Result: '.$val); } } } while ( ($countActiveThread + $countWaitThread) > 0); } } function l($str) { global $log_file,$charset; //echo $str; if($charset!=''){ echo iconv("cp1251", $charset, $str); }else{ echo $str; } if(is_file($log_file)){ file_put_contents($log_file, $str, FILE_APPEND); } } ?>