/** * @desc WHAT? * @author * @since 2012-07-23 17:08:27 * @throws 注意:无DB异常处理 * _ftp('iosfile','/ftp/dir/','/home/httpd/ios/xxx.rar') -> ftp:/ftp/dir/xxx.rar */ function _ftp($configName, $dir, $file) { $ftp_config = new ftp_config(); $interfaceConfig = $ftp_config->config[$configName]; if (!$interfaceConfig) { return false; } //连接FTP $t1 = microtime(true); $bool = $connRes = ftp_connect($interfaceConfig['host']); $diff_time = sprintf('%.5f', microtime(true) - $t1); if ($diff_time > 3) { _status(1, VHOST . '(BUG错误)', 'FTP超时(连接)', "{$configName}" . "@" . GET_INCLUDED_FILES, NULL, VIP, $diff_time); } _status(1, VHOST . '(FTP)', $interfaceConfig['host'], GET_INCLUDED_FILES, NULL, VIP, $diff_time); $t1 = microtime(true); $bool = ftp_login($connRes, $interfaceConfig['user_name'], $interfaceConfig['user_pass']); if (!$bool) { return false; } if ($interfaceConfig['dir'] != '/') { $bool = ftp_chdir($connRes, $interfaceConfig['dir']); } $dir_array = explode('/', $dir); if (count($dir_array)) { foreach ($dir_array as $v) { if (!$v) { continue; } ftp_mkdir($connRes, $v); ftp_chdir($connRes, $v); } } $diff_time = sprintf('%.5f', microtime(true) - $t1); if ($diff_time > 3) { _status(1, VHOST . '(BUG错误)', 'FTP超时(登录切换目录)', "{$configName}" . "@" . GET_INCLUDED_FILES, NULL, VIP, $diff_time); } $t1 = microtime(true); //上传文件 ftp_pasv($connRes, true); $bool = ftp_put($connRes, basename($file), $file, FTP_BINARY); $diff_time = sprintf('%.5f', microtime(true) - $t1); if ($diff_time > 3) { _status(1, VHOST . '(BUG错误)', 'FTP超时(上传)', "{$configName}" . "@" . GET_INCLUDED_FILES, NULL, VIP, $diff_time); } $diff_time_str = _debugtime($diff_time); if ($diff_time < 1) { _status(1, VHOST . '(FTP)', '一秒内', _debugtime($diff_time), $interfaceConfig['host'] . "@" . GET_INCLUDED_FILES . VIP, $configName, $diff_time); } else { _status(1, VHOST . '(FTP)', '超时', _debugtime($diff_time), $interfaceConfig['host'] . "@" . GET_INCLUDED_FILES . VIP, $configName, $diff_time); } return ftp_close($connRes); }
/** * @desc WHAT? * @author xing39393939@gmail.com * @since 2013-03-14 21:03:28 * @throws 注意:无DB异常处理 */ function increment($key, $num = 1, $flag = MEMCACHE_COMPRESSED, $expire = 0) { if (strpos(get_class($this), 'memcache_server') !== false) { $this->connect($key); } if ($this->memcacheObj) { $t1 = microtime(true); $bool = $this->memcacheObj->increment($key, $num); if ($bool === false) { //更新失败,是因为之前key存在,删除之后,还必须关闭连接再次连接回去 $this->memcacheObj->delete($key, 0); $this->close(); $this->connect($key); $this->memcacheObj->set($key, 0, $flag, $expire); $bool = $this->memcacheObj->increment($key, $num); } $diff_time = sprintf('%.5f', microtime(true) - $t1); _status(1, VHOST . '(Memcache)', "{$this->current_host['host']}:{$this->current_host['port']}(increment)", GET_INCLUDED_FILES, NULL, VIP, $diff_time); $diff_time_str = _debugtime($diff_time); _status(1, VHOST . '(Memcache)', $diff_time_str, "{$this->current_host['host']}:{$this->current_host['port']}(increment)", GET_INCLUDED_FILES, VIP, $diff_time); return $bool; } return false; }
/** * @desc 执行SQL查询语句 * @author * @since 2012-04-02 09:53:56 * @param resource $stmt 数据库句柄资源 * @return resource $error 错误信息 * @throws 无DB异常处理 */ function _ociexecute($stmt, $mode = OCI_COMMIT_ON_SUCCESS) { $last_oci_sql = $_SERVER['last_oci_sql']; $ADD_PROJECT = ADD_PROJECT; if (!is_resource($stmt)) { $debug_backtrace = debug_backtrace(); array_walk($debug_backtrace, create_function('&$v,$k', 'unset($v["function"],$v["args"]);')); _status(1, VHOST . "(BUG错误)", "SQL错误", GET_INCLUDED_FILES, "非资源\$stmt | " . var_export($_SERVER['last_oci_bindname'], true) . "|" . var_export($_GET, true) . "|" . $last_oci_sql . "|" . var_export($debug_backtrace, true)); } if (PROJECT_SQL === true) { $ADD_PROJECT = '[项目]'; } $_SERVER['oci_sql_ociexecute']++; $t1 = microtime(true); ociexecute($stmt, $mode); $diff_time = sprintf('%.5f', microtime(true) - $t1); //表格与函数关联 $sql_type = NULL; $v = _sql_table_txt($last_oci_sql, $sql_type); $out = array(); preg_match('# in(\\s+)?\\(#is', $last_oci_sql, $out); if ($out) { $last_oci_sql = substr($last_oci_sql, 0, stripos($last_oci_sql, ' in')) . ' in....'; _status(1, VHOST . "(BUG错误)", '问题SQL', "IN语法" . $ADD_PROJECT, "{$_SERVER['last_db_conn']}@" . GET_INCLUDED_FILES . "/{$_REQUEST['act']}", "{$last_oci_sql}"); } _status(1, VHOST . '(SQL统计)' . $ADD_PROJECT, "{$_SERVER['last_db_conn']}{$sql_type}", strtolower($v) . "@" . GET_INCLUDED_FILES, $last_oci_sql, VIP, $diff_time); $diff_time_str = _debugtime($diff_time); if ($diff_time < 1) { _status(1, VHOST . '(SQL统计)', '一秒内', _debugtime($diff_time), "{$_SERVER['last_db_conn']}." . strtolower($v) . "@" . GET_INCLUDED_FILES . VIP, $last_oci_sql, $diff_time); } else { _status(1, VHOST . '(SQL统计)', '超时', _debugtime($diff_time), "{$_SERVER['last_db_conn']}." . strtolower($v) . "@" . GET_INCLUDED_FILES . VIP, $last_oci_sql, $diff_time); } $ocierror = ocierror($stmt); if ($ocierror) { $debug_backtrace = debug_backtrace(); array_walk($debug_backtrace, create_function('&$v,$k', 'unset($v["function"],$v["args"]);')); _status(1, VHOST . "(BUG错误)", "SQL错误", GET_INCLUDED_FILES, var_export($ocierror, true) . '|' . var_export($_SERVER['last_oci_bindname'], true) . "|GET:" . var_export($_GET, true) . '|POST:' . var_export($_POST, true) . "|" . $last_oci_sql . "|" . var_export($debug_backtrace, true), VIP, $diff_time); } $_SERVER['last_oci_bindname'] = array(); return $ocierror; }
/** * @desc WHAT? * @author * @since 2012-06-17 23:04:10 * @throws 注意:无Db异常处理 */ function _curl(&$chinfo, $url, $post_data = null, $config = array(), $upload_file = array()) { settype($config, 'array'); $ch = curl_init(); $chinfo = array(); if (substr($url, 0, 5) == 'https') { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_ENCODING, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:', 'Accept-Encoding:gzip,deflate,sdch', 'User-Agent:Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0' . trim(GET_INCLUDED_FILES), "Referer:{$url}")); foreach ($config as $k => $v) { curl_setopt($ch, $k, $v); } if ($post_data) { if (function_exists('http_build_query')) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data)); } else { curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } } if ($upload_file) { curl_setopt($ch, CURLOPT_POSTFIELDS, (array) $upload_file + (array) $post_data); } $curl_error_tmp = $curl_error = NULL; $total_time = $i = 0; while (!$chinfo['http_code'] && $i <= 0) { $curl_data = curl_exec($ch); $curl_error_tmp = curl_error($ch); if ($curl_error_tmp) { $curl_error = $curl_error_tmp; } $chinfo = curl_getinfo($ch); $i++; $total_time += $chinfo['total_time']; } curl_close($ch); $url_path = explode('?', $chinfo['url']); $_SERVER['last_curl_info'][$url_path[0]] = $chinfo['url']; $_SERVER['last_curl_info_num']++; $chinfo['total_time'] = $total_time; $url_arr = parse_url($url); $url_arr_list = explode('.', $url_arr['host']); $url_arr_list_str = $url_arr_list[count($url_arr_list) - 2] . '.' . $url_arr_list[count($url_arr_list) - 1]; $debug_backtrace_str = NULL; foreach (debug_backtrace() as $vv) { $debug_backtrace_str .= "line:({$vv['line']}){$vv['function']}@file:{$vv['file']}\n"; } // if ($chinfo['http_code'] != '200' && $chinfo['http_code'][0] != '3') { _status(1, VHOST . '(BUG错误)', "网址抓取", "{$url_arr['host']}{$url_arr['path']}({$chinfo['http_code']})err:" . $curl_error, GET_INCLUDED_FILES . "\n{$chinfo['url']}\n{$debug_backtrace_str}", VIP, $total_time); } else { _status(1, VHOST . '(网址抓取)', $url_arr_list_str, "{$url_arr['host']}/{$url_arr['path']} ({$chinfo['http_code']})", GET_INCLUDED_FILES . "\n{$debug_backtrace_str}", VIP, $total_time); } //超时错误记录 if ($total_time < 1) { _status(1, VHOST . '(网址抓取)', '一秒内', _debugtime($total_time), $url_arr['host'] . "{$url_arr['path']} ({$chinfo['http_code']})" . $curl_error, GET_INCLUDED_FILES . "\n{$debug_backtrace_str}", $total_time); } else { _status(1, VHOST . '(网址抓取)', '超时', _debugtime($total_time), $url_arr['host'] . "{$url_arr['path']} ({$chinfo['http_code']})" . $curl_error, GET_INCLUDED_FILES . "\n{$debug_backtrace_str}", $total_time); } return $curl_data; }