/**
  * 
  */
 public function actionProxyLogReport()
 {
     self::$engines = [Proxy::GOOGLE, Proxy::YAHOO, Proxy::BING, Proxy::ASK, Proxy::ECOSIA];
     $results = \maxlen\proxy\models\ProxyLog::getDb()->createCommand("\n                SELECT pl.*, p.scope_id FROM proxy_log AS pl\n                LEFT JOIN " . Proxies::tableName(true) . " AS p ON p.host = pl.ip \n                WHERE pl.dt >= '" . date("Y-m-d", time() - 86400) . "' AND pl.dt <= '" . date("Y-m-d") . "'\n                 AND search_engine IN ('" . implode("','", self::$engines) . "')\n                 AND code = 302 ORDER BY pl.ip\n                ")->queryAll();
     $data = [];
     foreach ($results as $res) {
         if (!isset($data[$res['ip']])) {
             $tmpSe = [];
             foreach (self::$engines as $se) {
                 $tmpSe[$se] = 0;
             }
             $data[$res['ip']] = array_merge(['ip' => $res['ip'], 'scope' => $res['scope_id'], 'total' => 0], $tmpSe);
         }
         $data[$res['ip']][$res['search_engine']]++;
         $data[$res['ip']]['total']++;
     }
     if (!empty($data)) {
         \Yii::$app->mailer->compose("/proxyLogReport", ['count_total' => count($data), 'data' => $data])->setFrom('*****@*****.**')->setTo(['*****@*****.**', '*****@*****.**', '*****@*****.**'])->setSubject('Spider Log')->send();
     }
 }
Beispiel #2
0
 public function getProxyLog()
 {
     return $this->hasOne(ProxyLog::className(), array('ip' => 'host'));
 }
Beispiel #3
0
 /**
  * Check end wright to log proxy reply
  * 
  * @param array $proxy
  * @param array $curl_info - information about curl reply
  *              [
  *                      'http_code' - 302, 500 etc. (required)
  *              ]
  * @param int $timeout - pause in seconds (default 1 hour)
  * @return boolean
  */
 public static function checkProxyResponseCode($proxyIp, $curlInfo = ['http_code' => '302'], $searchEngine = self::GOOGLE, $timeout = 3600)
 {
     $proxyIp = trim($proxyIp);
     $proxyLog = ProxyLog::addToLog(['ip' => $proxyIp, 'search_engine' => $searchEngine, 'code' => $curlInfo['http_code'], 'url' => $curlInfo['url'], 'user_agent' => self::$userAgent, 'dt_unblock' => date('Y-m-d H:i:s', time() + $timeout)]);
     sleep(self::$proxyPause);
     if ($curlInfo['http_code'] != 200 && $proxyIp != '' && isset(static::$proxy[static::$proxyIndex])) {
         //            Log::casperQueryPicture(
         //                [
         //                    'url' => $curlInfo['url'],
         //                    'search_engine' => $searchEngine,
         //                    'proxy' => static::$proxy[static::$proxyIndex],
         //                    'proxyLog' => $proxyLog,
         //                    'code' => $curlInfo['http_code'],
         //                ]
         //            );
     }
     if ($curlInfo['http_code'] == 302 && $proxyIp != '') {
         foreach (static::$proxy as $key => $val) {
             if ($val['host'] == $proxyIp) {
                 next(static::$proxy);
                 static::$proxyIndex = key(static::$proxy);
                 unset(static::$proxy[$key]);
                 break;
             }
         }
         sleep(1);
         return false;
     }
     return true;
 }