Пример #1
0
 /**
  * Get scope of proxies
  * 
  * @param int $scope_id - number of proxies scope 
  * @param string $params = [
  *                  'searchEngine' - search engine ('google', 'yandex' ...)
  *                  'shuffle' - true|false - shuffle proxies array (default: false)
  * @return array
  */
 public static function getProxy($scope_id, array $params = ['searchEngine' => self::GOOGLE])
 {
     $params = Params::forGetProxy($params);
     if ($params['searchEngine'] == self::GOOGLE) {
         static::$antiCaptchaKey = \Yii::$app->params['proxy.settings']['AntiCaptchaKey'];
         static::$tmpFilePrefix = self::getPrefixFile();
     }
     if (count(static::$proxy) > 0) {
         static::$proxyIndex = key(static::$proxy);
     } else {
         static::$proxy = Proxies::getProxyPull($scope_id, $params['searchEngine']);
         if (isset($params['shuffle']) && $params['shuffle']) {
             $newProxies = [];
             $keys = array_keys(static::$proxy);
             shuffle($keys);
             foreach ($keys as $key) {
                 $newProxies[] = static::$proxy[$key];
             }
             static::$proxy = $newProxies;
         }
         static::$proxyIndex = key(static::$proxy);
     }
     self::setProxyPause();
     //        ProxyGetLog::addToLog(
     //            [
     //                'scope_id' => $scope_id,
     //                'se' => $params['searchEngine'],
     //                'return_proxies' => count(static::$proxy),
     //                'params' => json_encode($params),
     //            ]
     //        );
     return static::$proxy;
 }