Ejemplo n.º 1
0
 /**
  * load fresh proxy from gimmy proxy api.
  *
  * @todo: error handling
  */
 private function loadFreshProxy()
 {
     if (is_null($this->proxies)) {
         $this->proxies = new LinkedQueue();
     }
     if ($this->last_proxy + $this->max_reload_rate > time()) {
         //do not load new one because reload limit is violated
         return;
     }
     $this->last_proxy = time();
     $raw_return = file_get_contents('http://gimmeproxy.com/api/getProxy');
     $json = json_decode($raw_return, true);
     $this->proxies->enqueue(new Proxy($json['ip'], $json['port'], ProxyType::stringFactory($json['type']), 0, 0, 0, 0));
 }
Ejemplo n.º 2
0
 private function loadCSV($file_path)
 {
     $this->proxies = new LinkedQueue();
     if (($handle = fopen($file_path, 'r')) !== false) {
         while (($data = fgetcsv($handle, 1000, $this->delimiter)) !== false) {
             $cnum = count($data);
             //column num
             assert($cnum > 2, 'csv: not able detect mandatory columns');
             $ip = $data[0];
             $port = $data[1];
             $type = ProxyType::intFactory(intval($data[2]));
             $misses = $cnum > 3 ? $data[3] : 0;
             $hits = $cnum > 4 ? $data[4] : 0;
             $last_used = $cnum > 5 ? $data[5] : 0;
             $rating = $cnum > 6 ? $data[6] : 0;
             $this->proxies->enqueue(new Proxy($ip, $port, $type, $misses, $hits, $last_used, $rating));
         }
         fclose($handle);
     }
 }