private static function _get_content($ch, $maxredirect) { $redirect = 0; do { $retry = false; $ret = curl_exec($ch); BaseModelCommon::addStatInfo('request'); if (!self::_curl_check($ch)) { return false; } $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); if (in_array($code, array(301, 302, 303, 307), true)) { if (++$redirect <= $maxredirect) { defined('DAGGER_DEBUG') && BaseModelCommon::debug($redirect, 'request_redirect_times'); preg_match('/Location:(.*?)\\n/i', $ret, $matches); $newurl = trim($matches[1]); if ($newurl[0] === '/') { preg_match("@^([^/]+://[^/]+)/@", $url, $matches); $newurl = $matches[1] . $newurl; } curl_setopt($ch, CURLOPT_URL, $newurl); defined('DAGGER_DEBUG') && BaseModelCommon::debug($newurl, 'request_redirect_url'); $retry = true; } else { $msg = "redirect larger than {$maxredirect} [{$url}]"; defined('DAGGER_DEBUG') && BaseModelCommon::debug($msg, 'request_redirect_warn'); self::_error(90406, $msg); } } else { if ($code !== 200) { $msg = "http code unnormal : [{$code}] [{$url}] [{$ret}]"; defined('DAGGER_DEBUG') && BaseModelCommon::debug($msg, 'request_http_warn'); self::_error(90405, $msg); if (in_array($code, array(403, 404), true)) { return false; } } } } while ($retry); return $ret; }
/** * 调试结果 * @param string $sql * @param array $data * @return void */ protected function debugResult($result, $type = '') { $this->runTime = BaseModelCommon::addStatInfo('db', $this->runTime); if (defined('DAGGER_DEBUG')) { $arr = empty($type) ? array(array('运行时间', '查询结果'), array($this->runTime, $result)) : array(array('运行时间', '影响条目'), array($this->runTime, $result['affected_num'])); BaseModelCommon::debug($arr, 'db_sql_result'); } }
private function _checkStats($function, $times = 0, $native = false) { $runTime = 0; if (!empty($times)) { $runTime = BaseModelCommon::addStatInfo('mc', $this->startRunTime, $times); } $native = $this->native || $native; $code = $native ? $this->mcd->getResultCode() : $this->lastResultCode; if (in_array($code, array(Memcached::RES_SUCCESS, Memcached::RES_NOTFOUND), true)) { return $runTime; } else { if (in_array($function, array('add', 'addByKey', '_getLock'), true) && in_array($code, array(Memcached::RES_DATA_EXISTS, Memcached::RES_NOTSTORED), true)) { return $runTime; } } $errno = 90502; $error = $native ? $this->mcd->getResultMessage() : $this->lastResultMessage; defined('DAGGER_DEBUG') && BaseModelCommon::debug("[errro code] {$errno} [errro msg] {$error} [详细说明]:http://wiki.intra.sina.com.cn/display/dagger/{$errno}", 'request_error'); BaseModelLog::sendLog($errno, "[code]{$code}[msg]{$error}[method]{$function}[server]{$this->servers}", BaseModelException::getCodeName($errno), BaseModelLog::ERROR_MODEL_ID_MC); return $runTime; }