本文整理匯總了PHP中N函數的典型用法代碼示例。如果您正苦於以下問題:PHP N函數的具體用法?PHP N怎麽用?PHP N使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了N函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: showTime
/**
+----------------------------------------------------------
* 顯示運行時間、數據庫操作、緩存次數、內存使用信息
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
private function showTime()
{
// 顯示運行時間
G('beginTime', $GLOBALS['_beginTime']);
G('viewEndTime');
$showTime = 'Process: ' . G('beginTime', 'viewEndTime') . 's ';
// 顯示詳細運行時間
$showTime .= '( Load:' . G('beginTime', 'loadTime') . 's Init:' . G('loadTime', 'initTime') . 's Exec:' . G('initTime', 'viewStartTime') . 's Template:' . G('viewStartTime', 'viewEndTime') . 's )';
// 顯示數據庫操作次數
if (class_exists('Db', false)) {
$showTime .= ' | DB :' . N('db_query') . ' queries ' . N('db_write') . ' writes ';
}
// 顯示緩存讀寫次數
if (class_exists('Cache', false)) {
$showTime .= ' | Cache :' . N('cache_read') . ' gets ' . N('cache_write') . ' writes ';
}
// 顯示內存開銷
if (MEMORY_LIMIT_ON) {
$showTime .= ' | UseMem:' . number_format((memory_get_usage() - $GLOBALS['_startUseMems']) / 1024) . ' kb';
}
// 顯示文件加載數
$showTime .= ' | LoadFile:' . count(get_included_files());
// 顯示函數調用次數 自定義函數,內置函數
$fun = get_defined_functions();
$showTime .= ' | CallFun:' . count($fun['user']) . ',' . count($fun['internal']);
return $showTime;
}
示例2: set
/**
* 寫入緩存
* @access public
* @param string $name 緩存變量名
* @param mixed $value 存儲數據
* @param integer $expire 有效時間(秒)
* @return boolen
*/
public function set($name, $value, $expire = null)
{
N('cache_write', 1);
$expire = !empty($expireTime) ? $expireTime : C('DATA_CACHE_TIME');
$name = $this->options['prefix'] . sqlite_escape_string($name);
$value = sqlite_escape_string(serialize($value));
if (is_null($expire)) {
$expire = $this->options['expire'];
}
$expire = $expire == 0 ? 0 : time() + $expire;
//緩存有效期為0表示永久緩存
if (C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) {
//數據壓縮
$value = gzcompress($value, 3);
}
$sql = 'REPLACE INTO ' . $this->options['table'] . ' (var, value,expire) VALUES (\'' . $name . '\', \'' . $value . '\', \'' . $expire . '\')';
if (sqlite_query($this->handler, $sql)) {
if ($this->options['length'] > 0) {
// 記錄緩存隊列
$this->queue($name);
}
return true;
}
return false;
}
示例3: showTime
/**
* 顯示運行時間、數據庫操作、緩存次數、內存使用信息
* @access private
* @return string
*/
private function showTime()
{
// 顯示運行時間
G('beginTime', $GLOBALS['_beginTime']);
G('viewEndTime');
$showTime = 'Process: ' . G('beginTime', 'viewEndTime') . 's ';
if (C('SHOW_ADV_TIME')) {
// 顯示詳細運行時間
$showTime .= '( Load:' . G('beginTime', 'loadTime') . 's Init:' . G('loadTime', 'initTime') . 's Exec:' . G('initTime', 'viewStartTime') . 's Template:' . G('viewStartTime', 'viewEndTime') . 's )';
}
if (C('SHOW_DB_TIMES') && class_exists('Db', false)) {
// 顯示數據庫操作次數
$showTime .= ' | DB :' . N('db_query') . ' queries ' . N('db_write') . ' writes ';
}
if (C('SHOW_CACHE_TIMES') && class_exists('Cache', false)) {
// 顯示緩存讀寫次數
$showTime .= ' | Cache :' . N('cache_read') . ' gets ' . N('cache_write') . ' writes ';
}
if (MEMORY_LIMIT_ON && C('SHOW_USE_MEM')) {
// 顯示內存開銷
$showTime .= ' | UseMem:' . number_format((memory_get_usage() - $GLOBALS['_startUseMems']) / 1024) . ' kb';
}
if (C('SHOW_LOAD_FILE')) {
$showTime .= ' | LoadFile:' . count(get_included_files());
}
if (C('SHOW_FUN_TIMES')) {
$fun = get_defined_functions();
$showTime .= ' | CallFun:' . count($fun['user']) . ',' . count($fun['internal']);
}
return $showTime;
}
示例4: set
/**
+----------------------------------------------------------
* 寫入緩存
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 緩存變量名
* @param mixed $value 存儲數據
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function set($name, $value, $expire = '')
{
N('cache_write', 1);
if (empty($expire)) {
$expire = $this->expire;
}
return xcache_set($name, $value, $expire);
}
示例5: AK
static function AK(AL $e, E $c) : E
{
$f = 'AJ';
for ($g = 1, $h = N($c); $g < $e; $g++) {
$f .= $c;
}
return $f;
}
示例6: showTrace
/**
* 顯示頁麵Trace信息
* @access private
*/
private function showTrace()
{
// 係統默認顯示信息
$files = get_included_files();
$info = array();
foreach ($files as $key => $file) {
$info[] = $file . ' ( ' . number_format(filesize($file) / 1024, 2) . ' KB )';
}
$trace = array();
$base = array('請求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . __SELF__, '運行時間' => $this->showTime(), '內存開銷' => MEMORY_LIMIT_ON ? number_format((memory_get_usage() - $GLOBALS['_startUseMems']) / 1024, 2) . ' kb' : '不支持', '查詢信息' => N('db_query') . ' queries ' . N('db_write') . ' writes ', '文件加載' => count(get_included_files()), '緩存信息' => N('cache_read') . ' gets ' . N('cache_write') . ' writes ', '配置加載' => count(c()), '會話信息' => 'SESSION_ID=' . session_id());
// 讀取應用定義的Trace文件
$traceFile = CONF_PATH . 'trace.php';
if (is_file($traceFile)) {
$base = array_merge($base, include $traceFile);
}
$debug = trace();
$tabs = C('TRACE_PAGE_TABS', null, $this->tracePagTabs);
foreach ($tabs as $name => $title) {
switch (strtoupper($name)) {
case 'BASE':
// 基本信息
$trace[$title] = $base;
break;
case 'FILE':
// 文件信息
$trace[$title] = $info;
break;
default:
// 調試信息
if (strpos($name, '|')) {
// 多組信息
$array = explode('|', $name);
$result = array();
foreach ($array as $name) {
$result += isset($debug[$name]) ? $debug[$name] : array();
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($debug[$name]) ? $debug[$name] : '';
}
}
}
foreach ($trace as $key => $val) {
if (!is_array($val) && empty($val)) {
$val = array();
}
if (is_array($val)) {
$fire = array(array('', ''));
foreach ($val as $k => $v) {
$fire[] = array($k, $v);
}
fb(array($key, $fire), FirePHP::TABLE);
} else {
fb($val, $key);
}
}
unset($files, $info, $log, $base);
}
示例7: execute
/**
* 執行語句
*
* @access public
* @param string $str
* sql指令
* @param boolean $fetchSql
* 不執行隻是獲取SQL
* @return integer
*/
public function execute($str, $fetchSql = false)
{
$this->initConnect(true);
if (!$this->_linkID) {
return false;
}
$this->queryStr = $str;
if (!empty($this->bind)) {
$that = $this;
$this->queryStr = strtr($this->queryStr, array_map(function ($val) use($that) {
return '\'' . $that->escapeString($val) . '\'';
}, $this->bind));
}
if ($fetchSql) {
return $this->queryStr;
}
$flag = false;
if (preg_match("/^\\s*(INSERT\\s+INTO)\\s+(\\w+)\\s+/i", $str, $match)) {
$this->table = C("DB_SEQUENCE_PREFIX") . str_ireplace(C("DB_PREFIX"), "", $match[2]);
$flag = (bool) $this->query("SELECT * FROM user_sequences WHERE sequence_name='" . strtoupper($this->table) . "'");
}
// 釋放前次的查詢結果
if (!empty($this->PDOStatement)) {
$this->free();
}
$this->executeTimes++;
N('db_write', 1);
// 兼容代碼
// 記錄開始執行時間
$this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
if (false === $this->PDOStatement) {
$this->error();
return false;
}
foreach ($this->bind as $key => $val) {
if (is_array($val)) {
$this->PDOStatement->bindValue($key, $val[0], $val[1]);
} else {
$this->PDOStatement->bindValue($key, $val);
}
}
$this->bind = array();
$result = $this->PDOStatement->execute();
$this->debug(false);
if (false === $result) {
$this->error();
return false;
} else {
$this->numRows = $this->PDOStatement->rowCount();
if ($flag || preg_match("/^\\s*(INSERT\\s+INTO|REPLACE\\s+INTO)\\s+/i", $str)) {
$this->lastInsID = $this->_linkID->lastInsertId();
}
return $this->numRows;
}
}
示例8: set
/**
+----------------------------------------------------------
* 寫入緩存
*
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 緩存變量名
* @param mixed $value 存儲數據
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
function set($name, $value, $ttl = null)
{
N('cache_write', 1);
if (isset($ttl) && is_int($ttl)) {
$expire = $ttl;
} else {
$expire = $this->expire;
}
return apc_store($name, $value, $expire);
}
示例9: set
/**
+----------------------------------------------------------
* 寫入緩存
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 緩存變量名
* @param mixed $value 存儲數據
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function set($name, $value, $ttl = null)
{
N('cache_write', 1);
if (isset($ttl) && is_int($ttl)) {
$expire = $ttl;
} else {
$expire = $this->expire;
}
eaccelerator_lock($name);
return eaccelerator_put($name, $value, $expire);
}
示例10: set
/**
* 寫入緩存
* @access public
* @param string $name 緩存變量名
* @param mixed $value 存儲數據
* @param integer $expire 有效時間(秒)
* @return boolean
*/
public function set($name, $value, $expire = null)
{
N('cache_write', 1);
if (is_null($expire)) {
$expire = $this->options['expire'];
}
$name = $this->options['prefix'] . $name;
dump(json_encode(array('key' => $name, 'value' => $value, 'expire' => "" . $expire)));
dump($this->options['root']);
dump(file_post_contents($this->options['root'], json_encode(array('key' => $name, 'value' => $value, 'expire' => $expire))));
return true;
}
示例11: set
/**
+----------------------------------------------------------
* 寫入緩存
*
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 緩存變量名
* @param mixed $value 存儲數據
* @param integer $expire 有效時間(秒)
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function set($name, $value, $expire = null)
{
N('cache_write', 1);
if (is_null($expire)) {
$expire = $this->options['expire'];
}
if ($result = apc_store($name, $value, $expire)) {
if ($this->options['length'] > 0) {
// 記錄緩存隊列
$this->queue($name);
}
}
return $result;
}
示例12: showTrace
/**
* 顯示頁麵Trace信息
* @access private
*/
private function showTrace()
{
// 係統默認顯示信息
$files = get_included_files();
$info = [];
foreach ($files as $key => $file) {
$info[] = $file . ' ( ' . number_format(filesize($file) / 1024, 2) . ' KB )';
}
$trace = [];
Debug::remark('START', NOW_TIME);
$base = ['請求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['PHP_SELF'], '運行時間' => Debug::getUseTime('START', 'END', 6) . 's', '內存開銷' => MEMORY_LIMIT_ON ? G('START', 'END', 'm') . 'b' : '不支持', '查詢信息' => N('db_query') . ' queries ' . N('db_write') . ' writes ', '文件加載' => count($files), '緩存信息' => N('cache_read') . ' gets ' . N('cache_write') . ' writes ', '配置加載' => count(Config::get())];
// 讀取項目定義的Trace文件
$traceFile = MODULE_PATH . 'trace.php';
if (is_file($traceFile)) {
$base = array_merge($base, include $traceFile);
}
$debug = Log::getLog();
$tabs = Config::get('trace_page_tabs');
foreach ($tabs as $name => $title) {
switch (strtoupper($name)) {
case 'BASE':
// 基本信息
$trace[$title] = $base;
break;
case 'FILE':
// 文件信息
$trace[$title] = $info;
break;
default:
// 調試信息
$name = strtoupper($name);
if (strpos($name, '|')) {
// 多組信息
$array = explode('|', $name);
$result = [];
foreach ($array as $name) {
$result += isset($debug[$name]) ? $debug[$name] : [];
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($debug[$name]) ? $debug[$name] : '';
}
}
}
unset($files, $info, $base, $debug);
// 調用Trace頁麵模板
ob_start();
include Config::has('tmpl_trace_file') ? Config::get('tmpl_trace_file') : THINK_PATH . 'tpl/page_trace.tpl';
return ob_get_clean();
}
示例13: set
/**
+----------------------------------------------------------
* 寫入緩存
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 緩存變量名
* @param mixed $value 存儲數據
* @param integer $expire 有效時間(秒)
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function set($name, $value, $expire = null)
{
N('cache_write', 1);
if (is_null($expire)) {
$expire = $this->options['expire'];
}
if (wincache_ucache_set($name, $value, $expire)) {
if ($this->options['length'] > 0) {
// 記錄緩存隊列
$this->queue($name);
}
return true;
}
return false;
}
示例14: set
/**
* 寫入緩存
* @access public
* @param string $name 緩存變量名
* @param mixed $value 存儲數據
* @param integer $expire 有效時間(秒)
* @return boolen
*/
public function set($name, $value, $expire = null)
{
N('cache_write', 1);
if (is_null($expire)) {
$expire = $this->options['expire'];
}
$name = $this->options['prefix'] . $name;
if ($this->handler->set($name, $value, 0, $expire)) {
if ($this->options['length'] > 0) {
// 記錄緩存隊列
$this->queue($name);
}
return true;
}
return false;
}
示例15: execute
/**
* 執行語句
*
* @access public
* @param string $str
* sql指令
* @param boolean $fetchSql
* 不執行隻是獲取SQL
* @return mixed
*/
public function execute($str, $fetchSql = false)
{
$this->initConnect(true);
if (!$this->_linkID) {
return false;
}
$this->queryStr = $str;
if (!empty($this->bind)) {
$that = $this;
$this->queryStr = strtr($this->queryStr, array_map(function ($val) use($that) {
return '\'' . $that->escapeString($val) . '\'';
}, $this->bind));
}
if ($fetchSql) {
return $this->queryStr;
}
// 釋放前次的查詢結果
if (!empty($this->PDOStatement)) {
$this->free();
}
$this->executeTimes++;
N('db_write', 1);
// 兼容代碼
// 記錄開始執行時間
$this->debug(true);
$this->PDOStatement = $this->_linkID->prepare($str);
if (false === $this->PDOStatement) {
E($this->error());
}
foreach ($this->bind as $key => $val) {
if (is_array($val)) {
$this->PDOStatement->bindValue($key, $val[0], $val[1]);
} else {
$this->PDOStatement->bindValue($key, $val);
}
}
$this->bind = array();
$result = $this->PDOStatement->execute();
$this->debug(false);
if (false === $result) {
$this->error();
return false;
} else {
$this->numRows = $this->PDOStatement->rowCount();
return $this->numRows;
}
}