/** * Stop a benchmarking timer. * * $name should be the same as the $name used in startTimer(). * * @param string $name The name of the timer to end. * @access public * @return boolean true if timer was ended, false if timer was not started. * @static */ function stopTimer($name = null) { $end = getMicrotime(); $_this = DebugKitDebugger::getInstance(); if (!$name) { $names = array_reverse(array_keys($_this->__benchmarks)); foreach ($names as $name) { if (!empty($_this->__benchmarks[$name]['end'])) { continue; } if (empty($_this->__benchmarks[$name]['named'])) { break; } } } else { $i = 1; $_name = $name; while (isset($_this->__benchmarks[$name])) { if (empty($_this->__benchmarks[$name]['end'])) { break; } $i++; $name = $_name . ' #' . $i; } } if (!isset($_this->__benchmarks[$name])) { return false; } $_this->__benchmarks[$name]['end'] = $end; return true; }
function cached($url) { if (Configure::read('Cache.check') === true) { $path = $this->here; if ($this->here == '/') { $path = 'home'; } if($this->Session->check('Auth.User._id')){ //$path = $_SESSION['Auth']['User']['_id'].'_'.strtolower(Inflector::slug($path)); $path = '4d33940fda220a9606000003_'.strtolower(Inflector::slug($path)); }else{ $path = strtolower(Inflector::slug($path)); } $filename = CACHE . 'views' . DS . $path . '.php'; if (!file_exists($filename)) { $filename = CACHE . 'views' . DS . $path . '_index.php'; } if (file_exists($filename)) { if (!class_exists('View')) { App::import('View', 'View', false); } $controller = null; $view =& new View($controller); $return = $view->renderCache($filename, getMicrotime()); if (!$return) { ClassRegistry::removeObject('view'); } return $return; } } return false; }
public static function insertMessage($user_id, $chat_id, $message) { $conn = DbHandler::getConnection(); $query = "INSERT INTO messages (chat_id, user_id, message, insert_time) " . "VALUES (" . $conn->escapeString($chat_id) . ", " . $conn->escapeString($user_id) . ", '" . $conn->escapeString($message) . "', " . $conn->escapeString(getMicrotime()) . ")"; $conn->exec($query); UserHandler::setUserActivity(); return true; }
public function end() { if (is_null($this->startTime) || !is_null($this->endTime)) { return false; } $this->endTime = getMicrotime(); $this->elapsedTime = round($this->endTime - $this->startTime, 3); return true; }
/** * Stop a benchmarking timer. * * $name should be the same as the $name used in startTimer(). * * @param string $name The name of the timer to end. * @access public * @return boolean true if timer was ended, false if timer was not started. * @static */ function stopTimer($name = 'default') { $now = getMicrotime(); $_this = DebugKitDebugger::getInstance(); if (!isset($_this->__benchmarks[$name])) { return false; } $_this->__benchmarks[$name]['end'] = $now; return true; }
protected static function createUser($username) { require_once "handlers/ChatHandler.php"; $conn = DbHandler::getConnection(); $query = "INSERT INTO users (username, last_activity) VALUES ( '" . $conn->escapeString($username) . "', " . $conn->escapeString(getMicrotime()) . " )"; $conn->exec($query); $user_id = $conn->lastInsertRowID(); // add user rel to public chat ChatHandler::addUserChatRel($user_id, ChatHandler::PUBLIC_CHAT_ID); return $user_id; }
function endCount() { global $_runtime, $_SERVER, $db, $cac; $_runtime['Timer']['UserCodeFinished'] = getMicrotime(); $runtimecore = $_runtime['Timer']['InitFinished'] - $_runtime['Timer']['InitStart']; $runtimeuser = $_runtime['Timer']['UserCodeFinished'] - $_runtime['Timer']['UserCodeStart']; $runtimetotal = $runtimecore + $runtimeuser; $runtimeava = (file_get_contents(PROJECT_ROOT . '/p-ava.log') + $runtimetotal) / 2; file_put_contents(PROJECT_ROOT . '/p.log', sprintf('[Performance Log] Total Running time: %s (Core code %s, User code %s); Database query: %s (%s failed); Cache query: %sr / %sw; Men usage: %s kilobytes (peak: %s kilobytes); URL: %s' . "\r\n", $runtimetotal, $runtimecore, $runtimeuser, $db->count['Success'], $db->count['Failed'], $cac->count['Readed'], $cac->count['Written'], memory_get_usage(true) / 1024, memory_get_peak_usage(true) / 1024, $_SERVER['REQUEST_URI']), FILE_APPEND); file_put_contents(PROJECT_ROOT . '/p-ava.log', $runtimeava); }
function mysqlQuery($config, $request, $report) { $mysql = mysqlAccess($config); $start_time = getMicrotime(); // $show_time = true; if (!isset($request['mode'])) { $request['mode'] = 'SELECT'; } $request['model'] = $GLOBALS['model'][$GLOBALS['controller']]['model']; if ($GLOBALS['debug'] == true) { print_r($request); } $db_result = buildQuery($mysql, $request, $start_time, $report); // Return MySQL query result and query: return array('result' => $db_result['result'], 'query' => $db_result['query']); // Close MySQL connection: $mysql->close(); }
/** * 散列存储 * @param $savePath - 本地保存的路径 * @param $fileName - 原始文件名 * @param $isHashSaving - 是否散列存储。 * @param $randomFileName - 是否生成随机的Hash文件名。 * @return array **/ function hashFileSavePath($savePath, $fileName = '', $isHashSaving = true, $randomFileName = true) { $hashFileName = $randomFileName ? md5(randStr(20) . $fileName . getMicrotime() . uniqid()) : md5($fileName); $fileSaveDir = $savePath; $hashFilePath = ''; //是否散列存储。 if ($isHashSaving) { $hashFilePath = substr($hashFileName, 0, 1) . DIRECTORY_SEPARATOR . substr($hashFileName, 1, 2); $fileSaveDir = $savePath . DIRECTORY_SEPARATOR . $hashFilePath; } $fileInfo = array("file_path" => $hashFilePath, "file_name" => $hashFileName, "error" => 0); if (!is_dir($fileSaveDir)) { $result = mkdir($fileSaveDir, 0777, true); if (!$result) { $fileInfo["error"] = 1; } } return $fileInfo; }
/** * Queries the database with given SQL statement, and obtains some metadata about the result * (rows affected, timing, any errors, number of rows in resultset). The query is also logged. * If DEBUG is set, the log is shown all the time, else it is only shown on errors. * * @param string $sql * @return unknown */ function execute($sql) { $t = getMicrotime(); $this->_result = $this->_execute($sql); $this->affected = $this->lastAffected(); $this->took = round((getMicrotime() - $t) * 1000, 0); $this->error = $this->lastError(); $this->numRows = $this->lastNumRows($this->_result); if ($this->fullDebug && Configure::read() > 1) { $this->logQuery($sql); } if ($this->error) { $this->showQuery($sql); return false; } else { return $this->_result; } }
function _executeQuery($queryData = array (), $cache = true) { $t = getMicrotime(); $query = $this->_queryToString($queryData); if ($cache && isset ($this->_queryCache[$query])) { if (strpos(trim(strtolower($query)), $queryData['type']) !== false) { $res = $this->_queryCache[$query]; } } else { switch ($queryData['type']) { case 'search': // TODO pb ldap_search & $queryData['limit'] if ($res = @ ldap_search($this->connection, $queryData['targetDn'] . ',' . $this->config['basedn'], $queryData['conditions'], $queryData['fields'], 0, $queryData['limit'])) { if ($cache) { if (strpos(trim(strtolower($query)), $queryData['type']) !== false) { $this->_queryCache[$query] = $res; } } } else{ $res = false; } break; case 'delete': $res = @ ldap_delete($this->connection, $queryData['targetDn'] . ',' . $this->config['basedn']); break; default: $res = false; break; } } $this->_result = $res; $this->took = round((getMicrotime() - $t) * 1000, 0); $this->error = $this->lastError(); $this->numRows = $this->lastNumRows(); if ($this->fullDebug) { $this->logQuery($query); } return $this->_result; }
* Editing below this line should not be necessary. * Change at your own risk. * */ if (!defined('WEBROOT_DIR')) { define('WEBROOT_DIR', basename(dirname(__FILE__))); } if (!defined('WWW_ROOT')) { define('WWW_ROOT', dirname(__FILE__) . DS); } if (!defined('CORE_PATH')) { if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) { define('APP_PATH', null); define('CORE_PATH', null); } else { define('APP_PATH', ROOT . DS . APP_DIR . DS); define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS); } } if (!(include CORE_PATH . 'cake' . DS . 'bootstrap.php')) { trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR); } if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') { return; } else { $Dispatcher = new Dispatcher(); $Dispatcher->dispatch($url); } if (Configure::read() > 0) { echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->"; }
/** * Used to read records from the Datasource. The "R" in CRUD * * @param Model $model The model being read. * @param array $queryData An array of query data used to find the data you want * @return mixed */ public function read(&$model, $queryData = array()) { if (!isset($model->records) || !is_array($model->records) || empty($model->records)) { $this->_requestsLog[] = array('query' => 'Model ' . $model->alias, 'error' => __('No records found in model.', true), 'affected' => 0, 'numRows' => 0, 'took' => 0); return array($model->alias => array()); } $startTime = getMicrotime(); $data = array(); $i = 0; $limit = false; if (!isset($queryData['recursive'])) { $queryData['recursive'] = $model->recursive; } if (is_integer($queryData['limit']) && $queryData['limit'] > 0) { $limit = $queryData['page'] * $queryData['limit']; } foreach ($model->records as $pos => $record) { // Tests whether the record will be chosen if (!empty($queryData['conditions'])) { $queryData['conditions'] = (array) $queryData['conditions']; if (!$this->conditionsFilter($model, $record, $queryData['conditions'])) { continue; } } $data[$i][$model->alias] = $record; $i++; // Test limit if ($limit !== false && $i == $limit && empty($queryData['order'])) { break; } } if ($queryData['fields'] === 'COUNT') { $this->_registerLog($model, $queryData, getMicrotime() - $startTime, 1); if ($limit !== false) { $data = array_slice($data, ($queryData['page'] - 1) * $queryData['limit'], $queryData['limit'], false); } return array(array(array('count' => count($data)))); } // Order if (!empty($queryData['order'])) { if (is_string($queryData['order'][0])) { $field = $queryData['order'][0]; $alias = $model->alias; if (strpos($field, '.') !== false) { list($alias, $field) = explode('.', $field, 2); } if ($alias === $model->alias) { $sort = 'ASC'; if (strpos($field, ' ') !== false) { list($field, $sort) = explode(' ', $field, 2); } $data = Set::sort($data, '{n}.' . $model->alias . '.' . $field, $sort); } } } // Limit if ($limit !== false) { $data = array_slice($data, ($queryData['page'] - 1) * $queryData['limit'], $queryData['limit'], false); } // Filter fields if (!empty($queryData['fields'])) { $listOfFields = array(); foreach ($queryData['fields'] as $field) { if (strpos($field, '.') !== false) { list($alias, $field) = explode('.', $field, 2); if ($alias !== $model->alias) { continue; } } $listOfFields[] = $field; } foreach ($data as $id => $record) { foreach ($record[$model->alias] as $field => $value) { if (!in_array($field, $listOfFields)) { unset($data[$id][$model->alias][$field]); } } } } $this->_registerLog($model, $queryData, getMicrotime() - $startTime, count($data)); $_associations = $model->__associations; if ($queryData['recursive'] > -1) { foreach ($_associations as $type) { foreach ($model->{$type} as $assoc => $assocData) { $linkModel =& $model->{$assoc}; if ($model->useDbConfig == $linkModel->useDbConfig) { $db =& $this; } else { $db =& ConnectionManager::getDataSource($linkModel->useDbConfig); } if (isset($db)) { if (method_exists($db, 'queryAssociation')) { $stack = array($assoc); $db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $queryData, true, $data, $queryData['recursive'] - 1, $stack); } unset($db); } } } } if ($model->findQueryType === 'first') { if (!isset($data[0])) { $data = array(); } else { $data = array($data[0]); } } return $data; }
/** * Get all timers that have been started and stopped. * Calculates elapsed time for each timer. If clear is true, will delete existing timers * * @param bool $clear false * @return array * @access public **/ function getTimers($clear = false) { $_this =& DebugKitDebugger::getInstance(); $start = DebugKitDebugger::requestStartTime(); $now = getMicrotime(); $times = array(); if (!empty($_this->__benchmarks)) { $firstTimer = current($_this->__benchmarks); $_end = $firstTimer['start']; } else { $_end = $now; } $times['Core Processing (Derived)'] = array('message' => __d('debug_kit', 'Core Processing (Derived)', true), 'start' => 0, 'end' => $_end - $start, 'time' => round($_end - $start, 6), 'named' => null); foreach ($_this->__benchmarks as $name => $timer) { if (!isset($timer['end'])) { $timer['end'] = $now; } $times[$name] = array_merge($timer, array('start' => $timer['start'] - $start, 'end' => $timer['end'] - $start, 'time' => DebugKitDebugger::elapsedTime($name))); } if ($clear) { $_this->__benchmarks = array(); } return $times; }
function stopMicrotime($start_time) { return number_format(getMicrotime() - $start_time, 6) * 1000; }
function getMicrotimeDiff($start = 0) { return getMicrotime() - $start; }
<?php function getMicrotime() { list($usec, $sec) = explode(" ", microtime()); $usec_array = explode(".", $usec); return $usec_array[1]; } $timestamp = date('Y-m-d_H-i-s_') . getMicrotime(); $target_png = "converted/" . $timestamp . ".png"; $source_svg = "source_svg/" . $timestamp . ".svg"; $svg_xml = $_POST['svg_xml']; $svg_xml = stripslashes($svg_xml); if ($svg_xml == "") { die("no xml provided"); } file_put_contents($source_svg, $svg_xml); system("convert -background none " . $source_svg . " " . $target_png); system("chmod a+r converted/*"); echo "conversion/" . $target_png;
$_runtime['ScriptName'] = $cfg['facula']['PrimaryScript']; } $_runtime['ScriptFull'] = $site['APIFastCGI'] ? $_SERVER['QUERY_STRING'] : $_SERVER['PATH_INFO']; // Get the self url for web page if ($site['general']['SiteUrlRewrite'] && $site['HtaccessFileExisted']) { $_runtime['BaseURL'] = $_runtime['SelfRoot'] . $_runtime['ScriptFull']; $_runtime['RootURL'] = $_runtime['SelfRoot']; $_runtime['ActualBaseURL'] = $_runtime['ScriptRoot'] . $_runtime['ScriptFull']; $_runtime['ActualRootURL'] = $_runtime['ScriptRoot']; } else { $_runtime['BaseURL'] = $_runtime['SelfRoot'] . '/' . $_runtime['ScriptName'] . $_runtime['ScriptFull']; $_runtime['RootURL'] = $_runtime['SelfRoot'] . '/' . $_runtime['ScriptName']; $_runtime['ActualBaseURL'] = $_runtime['ScriptRoot'] . '/' . $_runtime['ScriptName'] . $_runtime['ScriptFull']; $_runtime['ActualRootURL'] = $_runtime['ScriptRoot'] . '/' . $_runtime['ScriptName']; } $_URLPARAM = url_parameters($_runtime['ScriptFull']); } // Init Template Engine $ui = new ui($cfg['template'], $site['general'], $_URLPARAM, $_runtime, $oops, $sec, $ses); unset($cfg['template'], $cfg['cache'], $cfg['db']); // Save all localsetting to sec class $sec->setLocalSetValue($cfg); unset($cfg, $site); // Set autoload. Great thanks to tabris17.cn@hotmail function __autoload($classname) { global $sec; return $sec->loadClass($classname); } $_runtime['Timer']['InitFinished'] = $_runtime['Timer']['UserCodeStart'] = getMicrotime();
/** * returnMicrotime method * * @return void * @access public */ public function returnMicrotime() { trigger_error(__FUNCTION__); return getMicrotime(); }
public function view_getNewGoodsList() { //调用action层, 获取列表数据 $start1 = getMicrotime(); $sku = $_GET['sku'] ? post_check(trim($_GET['sku'])) : ''; $purchaseId = intval($_GET['purchaseId']) > 0 ? intval($_GET['purchaseId']) : 0; $whId = intval($_GET['whId']) > 0 ? intval($_GET['whId']) : 1; $omAvailableAct = new OmAvailableAct(); $tName = 'pc_goods'; $select = 'spu'; $where = "WHERE is_delete=0 AND isNew=1 AND substring(sku, 1, 1)<>'M' AND substring(sku, 1, 1)<>'Z' and substring(sku, 1, 1)<>'F' "; if (!empty($sku)) { $where .= "AND sku like'{$sku}%' "; } if (!empty($purchaseId)) { $where .= "AND purchaseId='{$purchaseId}' "; } //第一步筛选,选出isNew=1,并且goodsName!=''和'无',sku不已F和Z开头的spu $spuList1 = $omAvailableAct->act_getTNameList($tName, $select, $where); $spuArr1 = array(); foreach ($spuList1 as $value) { if (!empty($value['spu'])) { $spuArr1[] = $value['spu']; } } //此时 $spuSkuRelationArr1中保存的是spu和sku的关系数组,形如 array('1201'=>array('1201_B','1201_W'),'1202'=>array('1202')); //此时 $spuSkuRelationArr1中保存的是spu和sku的关系数组,形如 array('1201'=>array('1201_B','1201_W'),'1202'=>array('1202')); //第二步,选择出制作表已经存在的数据 $tName = 'pc_products'; $select = 'sku'; $where = "WHERE is_delete=0 "; $skuList2 = OmAvailableModel::getTNameList($tName, $select, $where); $spuArr2 = array(); foreach ($skuList2 as $value) { $tmpArr = explode('_', $value['sku']); if (!empty($tmpArr[0])) { $spu = $tmpArr[0]; $spuArr2["{$spu}"] = $spu; //SPU } } //第三步,找出新品领料单中存在的sku; $tName = 'pc_products_iostore_detail'; $select = 'sku'; $where = "WHERE is_delete=0 AND iostoreTypeId=1 AND useTypeId=1 AND isAudit<3 "; $skuList3 = OmAvailableModel::getTNameList($tName, $select, $where); $spuArr3 = array(); foreach ($skuList3 as $value) { $tmpArr = explode('_', $value['sku']); if (!empty($tmpArr[0])) { $spu = $tmpArr[0]; $spuArr3["{$spu}"] = $spu; //SPU } } $saveSpuArr = array(); //要保留的SPU foreach ($spuArr1 as $value) { if (!in_array($value, $spuArr2, true) && !in_array($value, $spuArr3, true)) { //SPU不在$spuArr2,$spuArr3时保留 $saveSpuArr[] = "'" . $value . "'"; } $saveSpuArr = array(); //要保留的SPU foreach ($spuArr1 as $value) { if (!in_array($value, $spuArr2) && !in_array($value, $spuArr3)) { //SPU不在$spuArr2,$spuArr3时保留 $saveSpuArr[] = "'" . $value . "'"; } } if (empty($saveSpuArr)) { $saveSpuStr = "'0'"; } else { $saveSpuStr = implode(',', $saveSpuArr); } $tName = 'pc_goods'; $select = 'spu,sku,isNew'; $where = "WHERE is_delete=0 AND spu IN({$saveSpuStr})"; $skuList4 = OmAvailableModel::getTNameList($tName, $select, $where); $spuSkuRelationArr1 = array(); $unSaveSpu = ''; } $tName = 'pc_goods'; $select = 'spu,sku,isNew'; $where = "WHERE is_delete=0 AND spu IN({$saveSpuStr})"; $skuList4 = OmAvailableModel::getTNameList($tName, $select, $where); $spuSkuRelationArr1 = array(); $unSaveSpu = ''; foreach ($skuList4 as $value) { if ($value['isNew'] == 0) { //过滤出全是新品的SPU $unSaveSpu = $value['spu']; } if ($unSaveSpu == $value['spu']) { continue; } $spuSkuRelationArr1[$value['spu']][] = $value['sku']; } $skuArr4 = array(); foreach ($skuList4 as $value) { $skuArr4[] = "'" . $value['sku'] . "'"; } if (empty($skuArr4)) { $skuArrStr = "'0'"; } else { $skuArrStr = implode(',', $skuArr4); } $tName = 'pc_goods_whId_location_raletion'; $select = 'sku'; $where = "WHERE location<>'' AND sku In({$skuArrStr}) "; $where .= "AND whId={$whId} "; $skuList5 = OmAvailableModel::getTNameList($tName, $select, $where); $spuSkuRelationArr2 = array(); foreach ($skuList5 as $value) { $tmpSpuArr = explode('_', $value['sku']); if (!empty($tmpSpuArr[0])) { $spuSkuRelationArr2[$tmpSpuArr[0]][] = $value['sku']; } } $spuLastArr = array(); foreach ($spuSkuRelationArr1 as $spu => $skuArr) { $tmpArray = $spuSkuRelationArr2[$spu]; if (count($skuArr) == count($tmpArray)) { $spuLastArr[] = "'" . $spu . "'"; } } if (empty($spuLastArr)) { $spuLastStr = "'0'"; } else { $spuLastStr = implode(',', $spuLastArr); } $tName = 'pc_goods'; $select = 'spu,sku,goodsName,purchaseId,goodsCreatedTime'; $where = "WHERE is_delete=0 AND spu IN({$spuLastStr})"; $total = $omAvailableAct->act_getTNameCount($tName, $where); $num = 1000; //每页显示的个数 $page = new Page($total, $num, '', 'CN'); $where .= "order by sku " . $page->limit; $newGoodsList = $omAvailableAct->act_getTNameList($tName, $select, $where); $total = $omAvailableAct->act_getTNameCount($tName, $where); $num = 1000; //每页显示的个数 $page = new Page($total, $num, '', 'CN'); $where .= "order by sku " . $page->limit; $newGoodsList = $omAvailableAct->act_getTNameList($tName, $select, $where); if (!empty($_GET['page'])) { if (intval($_GET['page']) <= 1 || intval($_GET['page']) > ceil($total / $num)) { $n = 1; } else { $n = (intval($_GET['page']) - 1) * $num + 1; } } else { $n = 1; } if ($total > $num) { //输出分页显示 $show_page = $page->fpage(array(0, 2, 3, 4, 5, 6, 7, 8, 9)); } else { $show_page = $page->fpage(array(0, 2, 3)); } $navlist = array(array('url' => 'index.php?mod=products&act=getProductsComfirmList', 'title' => '产品制作'), array('url' => 'index.php?mod=products&act=getProductsComfirmList', 'title' => '新品列表')); $this->smarty->assign('navlist', $navlist); $this->smarty->assign('onevar', 5); $this->smarty->assign('twovar', 55); $this->smarty->assign('show_page', $show_page); $this->smarty->assign('title', '新品列表'); $whInfo = getWhInfo(); $whArr = array(); foreach ($whInfo as $value) { $whArr[$value['id']] = $value['whName']; } if (!empty($newGoodsList)) { $countNewGL = count($newGoodsList); for ($i = 0; $i < $countNewGL; $i++) { $tName = 'pc_goods_whId_location_raletion'; $select = '*'; $where = "WHERE sku='{$newGoodsList[$i]['sku']}' "; $skuInfoList = OmAvailableModel::getTNameList($tName, $select, $where); $newGoodsList[$i]['whId'] = $skuInfoList[0]['whId']; $newGoodsList[$i]['wh'] = $whArr[$skuInfoList[0]['whId']]; $newGoodsList[$i]['location'] = $skuInfoList[0]['location']; $newGoodsList[$i]['storageTime'] = $skuInfoList[0]['storageTime']; } } $end1 = getMicrotime(); //echo $end1-$start1;exit; $this->smarty->assign('newGoodsList', empty($newGoodsList) ? array() : $newGoodsList); $this->smarty->display("newGoodsList.htm"); }
/** * Outputs cached dispatch view cache * * @param string $url Requested URL * @access public */ function cached($url) { if (Configure::read('Cache.check') === true) { $path = $this->here; if ($this->here == '/') { $path = 'home'; } $path = strtolower(Inflector::slug($path)); $filename = CACHE . 'views' . DS . $path . '.php'; if (!file_exists($filename)) { $filename = CACHE . 'views' . DS . $path . '_index.php'; } if (file_exists($filename)) { if (!class_exists('View')) { App::import('View', 'View', false); } $controller = null; $view =& new View($controller); $return = $view->renderCache($filename, getMicrotime()); if (!$return) { ClassRegistry::removeObject('view'); } return $return; } } return false; }
function _executeQuery($queryData = array(), $cache = true) { $t = getMicrotime(); $pattern = '/,[ \\t]+(\\w+)=/'; $queryData['targetDn'] = preg_replace($pattern, ',$1=', $queryData['targetDn']); if ($this->checkBaseDn($queryData['targetDn']) == 0) { $this->log("Missing BaseDN in " . $queryData['targetDn'], 'debug'); if ($queryData['targetDn'] != null) { $seperator = substr($queryData['targetDn'], -1) == ',' ? '' : ','; if (strpos($queryData['targetDn'], '=') === false && (isset($this->model) && !empty($this->model))) { //Fix TargetDN here $key = $this->model->primaryKey; $table = $this->model->useTable; $queryData['targetDn'] = $key . '=' . $queryData['targetDn'] . ', ' . $table . $seperator . $this->config['basedn']; } else { $queryData['targetDn'] = $queryData['targetDn'] . $seperator . $this->config['basedn']; } } else { $queryData['targetDn'] = $this->config['basedn']; } } $query = $this->_queryToString($queryData); if ($cache && isset($this->_queryCache[$query])) { if (strpos(trim(strtolower($query)), $queryData['type']) !== false) { $res = $this->_queryCache[$query]; } } else { switch ($queryData['type']) { case 'search': // TODO pb ldap_search & $queryData['limit'] if (empty($queryData['fields'])) { $queryData['fields'] = $this->defaultNSAttributes(); } //Handle LDAP Scope if (isset($queryData['scope']) && $queryData['scope'] == 'base') { $res = @ldap_read($this->database, $queryData['targetDn'], $queryData['conditions'], $queryData['fields']); } elseif (isset($queryData['scope']) && $queryData['scope'] == 'one') { $res = @ldap_list($this->database, $queryData['targetDn'], $queryData['conditions'], $queryData['fields']); } else { if ($queryData['fields'] == 1) { $queryData['fields'] = array(); } $res = @ldap_search($this->database, $queryData['targetDn'], $queryData['conditions'], $queryData['fields'], 0, $queryData['limit']); } if (!$res) { $res = false; $errMsg = ldap_error($this->database); $this->log("Query Params Failed:" . print_r($queryData, true) . ' Error: ' . $errMsg, 'ldap.error'); $this->count = 0; } else { $this->count = ldap_count_entries($this->database, $res); } if ($cache) { if (strpos(trim(strtolower($query)), $queryData['type']) !== false) { $this->_queryCache[$query] = $res; } } break; case 'delete': $res = @ldap_delete($this->database, $queryData['targetDn'] . ',' . $this->config['basedn']); break; default: $res = false; break; } } $this->_result = $res; $this->took = round((getMicrotime() - $t) * 1000, 0); $this->error = $this->lastError(); $this->numRows = $this->lastNumRows(); if ($this->fullDebug) { $this->logQuery($query); } return $this->_result; }
/** * Render cached view * * @param string $filename the cache file to include * @param string $timeStart the page render start time */ function renderCache($filename, $timeStart) { ob_start(); include $filename; if (Configure::read() > 0 && $this->layout != 'xml') { echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->"; } $out = ob_get_clean(); if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match)) { if (time() >= $match['1']) { @unlink($filename); unset($out); return false; } else { if ($this->layout === 'xml') { header('Content-type: text/xml'); } echo str_replace('<!--cachetime:' . $match['1'] . '-->', '', $out); return true; } } }
/** * handleFXResult * * logs queries, logs errors, and returns false on error * * @param FX result object or FX error object * @param string : model name * @param string : action name * * @return false if result is an FX error object */ function handleFXResult($result, $modelName = 'N/A', $actionName = 'N/A') { $this->_queriesCnt++; // if a connection error if (FX::isError($result)) { // log error $this->_queriesLog[] = array('model' => $modelName, 'action' => $actionName, 'query' => '', 'error' => $result->toString(), 'numRows' => '', 'took' => round((getMicrotime() - $this->timeFlag) * 1000, 0)); if (count($this->_queriesLog) > $this->_queriesLogMax) { array_pop($this->_queriesLog); } CakeLog::write('error', $this->formatErrorMessage('FX Error', $result->toString(), $modelName, $actionName)); $this->timeFlag = getMicrotime(); return FALSE; // if a filemaker error other than no records found } elseif ($result['errorCode'] != 0 && $result['errorCode'] != 401) { // log error $this->_queriesLog[] = array('model' => $modelName, 'action' => $actionName, 'query' => substr($result['URL'], strrpos($result['URL'], '?')), 'error' => $result['errorCode'], 'numRows' => '', 'took' => round((getMicrotime() - $this->timeFlag) * 1000, 0)); if (count($this->_queriesLog) > $this->_queriesLogMax) { array_pop($this->_queriesLog); } CakeLog::write('error', $this->formatErrorMessage('FileMaker Error', $result['errorCode'], $modelName, $actionName, substr($result['URL'], strrpos($result['URL'], '?')))); $this->timeFlag = getMicrotime(); return FALSE; } else { // log query $this->_queriesLog[] = array('model' => $modelName, 'action' => $actionName, 'query' => substr($result['URL'], strrpos($result['URL'], '?')), 'error' => $result['errorCode'], 'numRows' => isset($result['data']) ? count($result['data']) : $result['foundCount'], 'took' => round((getMicrotime() - $this->timeFlag) * 1000, 0)); $this->timeFlag = getMicrotime(); return TRUE; } }
/** * Outputs cached dispatch for js, css, img, view cache * * @param string $url Requested URL * @access public */ function cached($url) { if (strpos($url, 'css/') !== false || strpos($url, 'js/') !== false || strpos($url, 'img/') !== false) { if (strpos($url, 'ccss/') === 0) { include WWW_ROOT . DS . Configure::read('Asset.filter.css'); $this->_stop(); } elseif (strpos($url, 'cjs/') === 0) { include WWW_ROOT . DS . Configure::read('Asset.filter.js'); $this->_stop(); } $isAsset = false; $assets = array('js' => 'text/javascript', 'css' => 'text/css', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'png' => 'image/png'); $ext = array_pop(explode('.', $url)); foreach ($assets as $type => $contentType) { if ($type === $ext) { $parts = explode('/', $url); if ($parts[0] === 'css' || $parts[0] === 'js' || $parts[0] === 'img') { $pos = 0; } else { $pos = strlen($parts[0]); } $isAsset = true; break; } } if ($isAsset === true) { $ob = @ini_get("zlib.output_compression") !== '1' && extension_loaded("zlib") && strpos(env('HTTP_ACCEPT_ENCODING'), 'gzip') !== false; if ($ob && Configure::read('Asset.compress')) { ob_start(); ob_start('ob_gzhandler'); } $assetFile = null; $paths = array(); if ($pos > 0) { $plugin = substr($url, 0, $pos); $url = preg_replace('/^' . preg_quote($plugin, '/') . '\\//i', '', $url); $pluginPaths = Configure::read('pluginPaths'); $count = count($pluginPaths); for ($i = 0; $i < $count; $i++) { $paths[] = $pluginPaths[$i] . $plugin . DS . 'vendors' . DS; } } $paths = array_merge($paths, Configure::read('vendorPaths')); foreach ($paths as $path) { if (is_file($path . $url) && file_exists($path . $url)) { $assetFile = $path . $url; break; } } if ($assetFile !== null) { $fileModified = filemtime($assetFile); header("Date: " . date("D, j M Y G:i:s ", $fileModified) . 'GMT'); header('Content-type: ' . $assets[$type]); header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT"); header("Cache-Control: cache"); header("Pragma: cache"); if ($type === 'css' || $type === 'js') { include $assetFile; } else { readfile($assetFile); } if (Configure::read('Asset.compress')) { ob_end_flush(); } return true; } } } if (Configure::read('Cache.check') === true) { $path = $this->here; if ($this->here == '/') { $path = 'home'; } $path = strtolower(Inflector::slug($path)); $filename = CACHE . 'views' . DS . $path . '.php'; if (!file_exists($filename)) { $filename = CACHE . 'views' . DS . $path . '_index.php'; } if (file_exists($filename)) { if (!class_exists('View')) { App::import('Core', 'View'); } $controller = null; $view =& new View($controller); $return = $view->renderCache($filename, getMicrotime()); if (!$return) { ClassRegistry::removeObject('view'); } return $return; } } return false; }
/** * admin_build_index method * * Build or refresh the search index. This is an intensive method! * If $clear evaluates to true, the existing index folder will be deleted. This ensures that all file permissions * are as expected. * A time limit of 2s per current revision is set - which should be sufficient even on a loaded/low power * machine. Small sections take ~0.1 to index, large sections can take upto 30s * * @param bool $clear * @return void * @access public */ function admin_build_index($clear = false) { $count = $this->Revision->find('count', array('status' => 'current')); set_time_limit(max(30, $count) * 2); if ($clear) { if (file_exists(TMP . 'search_index')) { $folder = new Folder(TMP . 'search_index'); if (!$folder->delete()) { $this->Session->setFlash('The search index folder "' . TMP . 'search_index/" could not be deleted!<br />Manually delete this folder, ensure that the webuser can write to "' . TMP . '", and try again'); $this->redirect(array('action' => 'index')); } $this->Session->setFlash('The search index "' . TMP . 'search_index" was deleted'); } } $start = getMicrotime(); $this->Revision->build_index(); $this->Session->setFlash('Search index rebuilt'); if (Configure::read()) { $time = round(getMicrotime() - $start, 1); $this->log('Clearing cache files ' . $time . 's', 'searchable'); } clearCache(); if (Configure::read()) { $time = round(getMicrotime() - $start, 1); $this->log('Cache cleared ' . $time . 's', 'searchable'); } $this->redirect(array('action' => 'index')); }
* @since CakePHP(tm) v 0.2.9 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ if (!defined('PHP5')) { define('PHP5', PHP_VERSION >= 5); } if (!defined('E_DEPRECATED')) { define('E_DEPRECATED', 8192); } if (!defined('E_STRICT')) { define('E_STRICT', 2048); } error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); /** * Configuration, directory layout and standard libraries */ if (!isset($bootstrap)) { require CORE_PATH . 'cake' . DS . 'basics.php'; $TIME_START = getMicrotime(); require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php'; require LIBS . 'object.php'; require LIBS . 'inflector.php'; require LIBS . 'configure.php'; } require LIBS . 'cache.php'; Configure::getInstance(); $url = null; require CAKE . 'dispatcher.php';
define('TMP', dirname(ROOT) . DS . 'data' . DS . 'web' . DS); } if (!defined('CAKE_CORE_INCLUDE_PATH')) { define('CAKE_CORE_INCLUDE_PATH', ROOT); } if (!defined('WWW_ROOT')) { define('WWW_ROOT', dirname(__FILE__) . '/'); } $path = dirname(ROOT) . DS . 'data' . DS . '/database.php'; if (!file_exists($path)) { $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); $host = 'http://' . $host; header('Location:' . $host . '/tools/installs'); exit; } if (!defined('CORE_PATH')) { define('APP_PATH', ROOT . DS . APP_DIR . DS); define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS); } if (!(include CORE_PATH . 'cake' . DS . 'bootstrap.php')) { trigger_error('CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your ' . DS . 'cake core directory and your ' . DS . 'vendors root directory.', E_USER_ERROR); } if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') { return; } else { $Dispatcher = new Dispatcher(); $Dispatcher->dispatch(); } if (Configure::read() > 0) { echo '<!-- ' . round(getMicrotime() - $TIME_START, 4) . 's -->'; }
/** * Queries the database with given SQL statement, and obtains some metadata about the result * (rows affected, timing, any errors, number of rows in resultset). The query is also logged. * If Configure::read('debug') is set, the log is shown all the time, else it is only shown on errors. * * ### Options * * - stats - Collect meta data stats for this query. Stats include time take, rows affected, * any errors, and number of rows returned. Defaults to `true`. * - log - Whether or not the query should be logged to the memory log. * * @param string $sql * @param array $options * @return mixed Resource or object representing the result set, or false on failure * @access public */ function execute($sql, $options = array()) { $defaults = array('stats' => true, 'log' => $this->fullDebug); $options = array_merge($defaults, $options); $t = getMicrotime(); $this->_result = $this->_execute($sql); if ($options['stats']) { $this->took = round((getMicrotime() - $t) * 1000, 0); $this->affected = $this->lastAffected(); $this->error = $this->lastError(); $this->numRows = $this->lastNumRows(); } if ($options['log']) { $this->logQuery($sql); } if ($this->error) { $this->showQuery($sql); return false; } return $this->_result; }
if ($config['open'] == 0 || $c_log) { ?> <div class="menu"><a href="./">留言</a> | <a href="?m=album">照片</a> | <a href="?m=camp">活动</a> | <a href="?m=user">成员</a><?php if ($c_log) { $s_dbg = sprintf('select id from %s where tid=%s and readed=1', $dbprefix . 'message', $_SESSION[$config['u_hash']]); $q_dbg = mysql_query($s_dbg) or die(''); $c_dbg = mysql_num_rows($q_dbg); mysql_free_result($q_dbg); echo ' | <a href="?m=message">消息</a>' . ($c_dbg > 0 ? '<span class="message_n">' . $c_dbg . '</span>' : '') . str_repeat(' ', 10) . '<a href="?m=logout">退出</a>'; } ?> </div><?php } ?> <div class="content"> <?php echo $content; ?> </div> <div class="foot">© <?php echo date('Y', getftime()) . ' ' . ($config['classname'] != '' ? ($config['school'] != '' ? $config['school'] . ' ' : '') . $config['classname'] : $config['title']); ?> <br/>掌上版 | <a href="../">普通版</a> <a href="http://www.piscdong.com/mini_class/" rel="external"><img src="../images/powered.gif" alt="" title="Powered by 迷你同学录"/></a></div> </div> <div style="display: none;"><iframe src="../sync_e.php" width="1" height="1" frameborder="0"></iframe></div> </body> </html> <!-- <?php echo (getMicrotime() - $mt) * 1000; ?> ms. -->