private static function exeBySetTimes($count, $curl) { $result = curl_exec($curl); if (curl_errno($curl)) { LogUtils::debug("请求错误: " . curl_errno($curl)); if ($count > 0) { $count--; $result = HttpManager::exeBySetTimes($count, $curl); } } return $result; }
public static function getFastestRealTime($hosts) { $mint = 60.0; $s_url = ""; for ($i = 0; $i < count($hosts); $i++) { $start = array_sum(explode(" ", microtime())); try { $homepage = HttpManager::httpHead($hosts[$i]); } catch (Exception $e) { echo $e; } $ends = array_sum(explode(" ", microtime())); $diff = $ends - $start; if ($mint > $diff) { $mint = $diff; $s_url = $hosts[$i]; } } return $s_url; }
/** * @param $count * @param $curl * @return mixed */ private static function exeBySetTimes($count, $curl) { $result = curl_exec($curl); if (curl_errno($curl)) { LogUtils::debug('请求错误: ' . curl_errno($curl)); if ($count > 0) { sleep(3); //Sleep 3 seconds to save cpu power $count--; $result = HttpManager::exeBySetTimes($count, $curl); } } return $result; }
public function close() { $params = array(); $params["action"] = "close"; $params["appkey"] = $this->appKey; HttpManager::httpPostJson($this->host, $params, false); }
private static function exeBySetTimes($count, $curl) { $result = curl_exec($curl); $info = curl_getinfo($curl); $code = $info["http_code"]; if (curl_errno($curl) != 0 && $code != 200) { LogUtils::debug("request errno: " . curl_errno($curl) . ",url:" . $info["url"]); $count--; if ($count > 0) { $result = HttpManager::exeBySetTimes($count, $curl); } } return $result; }
/** * @throws RequestException */ public function close() { $params = array(); $params['action'] = 'close'; $params['appkey'] = $this->appkey; HttpManager::httpPostJson($this->host, $params, false); }