Blame view

src/lib/models/proxy.php 1.73 KB
ef60cd4d   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  <?php
  
  class proxy extends \Phalcon\Mvc\Model
  {
      public $id;
      public $proxy;
      public $status;
      static $instance;
      private $next_proxy;
      private $proxy_active;
  
      public static function getInstance(){
          if(empty(self::$instance)){
              self::$instance = new proxy();
          }
          return self::$instance;
      }
  
  
      public function getProxy(){
          $this->proxy_active = self::find('status = 1')->toArray();
          if( $this->proxy_active ){
              $count = count($this->proxy_active);
              if(!$this->next_proxy){
                  $this->next_proxy = 0;
                  print('use proxy '.$this->proxy_active[$this->next_proxy++]['proxy']);
                  return $this->proxy_active[$this->next_proxy++]['proxy'];
              }else {
                  if($this->next_proxy >= $count-1){
                      $this->next_proxy = 0;
                      print('use proxy '.$this->proxy_active[$this->next_proxy++]['proxy']);
                      return $this->proxy_active[$this->next_proxy]['proxy'];
                  } else {
                      print('use proxy '.$this->proxy_active[$this->next_proxy++]['proxy']);
                      return $this->proxy_active[$this->next_proxy++]['proxy'];
                  }
              }
          } else {
              die('you don\'t have proxy');
          }
  
  
      }
  
      public function deleteProxy(){
          $activ_proxy = $this->next_proxy? $this->next_proxy - 1: $this->next_proxy;
          print('delete proxy '.$this->proxy_active[$activ_proxy]['proxy']);
          $non_active_proxy = self::findFirst('id = '.$this->proxy_active[$activ_proxy]['id']);
          $non_active_proxy->status = 0;
          $non_active_proxy->save();
      }
  
      public function initialize()
      {
  
      }
  
  
  }