本文整理汇总了PHP中Timer::get_duration方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::get_duration方法的具体用法?PHP Timer::get_duration怎么用?PHP Timer::get_duration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::get_duration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dbprune
/**
* Auto pruning of old stats.
*
* It uses a general setting to store the day of the last prune, avoiding multiple prunes per day.
* fplanque>> Check: How much faster is this than DELETING right away with an INDEX on the date field?
*
* Note: we're using {@link $localtimenow} to log hits, so use this for pruning, too.
*
* NOTE: do not call this directly, but only in conjuction with auto_prune_stats_mode.
*
* @return array array(
* 'result' => 'error' | 'ok'
* 'message' => Message of the error or result data
* )
*/
static function dbprune()
{
/**
* @var DB
*/
global $DB;
global $Debuglog, $Settings, $localtimenow;
global $Plugins, $Messages;
// Prune when $localtime is a NEW day (which will be the 1st request after midnight):
$last_prune = $Settings->get('auto_prune_stats_done');
if ($last_prune >= date('Y-m-d', $localtimenow) && $last_prune <= date('Y-m-d', $localtimenow + 86400)) {
// Already pruned today (and not more than one day in the future -- which typically never happens)
$message = T_('Pruning has already been done today');
$Messages->add($message, 'error');
return array('result' => 'error', 'message' => $message);
}
// Get tables info
global $db_config;
$tables = array();
$tables_info = $DB->get_results('SHOW TABLE STATUS WHERE Name IN ( ' . $DB->quote(array('T_hitlog', 'T_sessions', 'T_basedomains')) . ' )');
foreach ($tables_info as $table_info) {
$tables[$table_info->Name] = array('type' => $table_info->Engine, 'rows' => $table_info->Rows);
}
// Init Timer for hitlist
// Note: Don't use global $Timer because it works only in debug mode
load_class('_core/model/_timer.class.php', 'Timer');
$hitlist_Timer = new Timer('prune_hits');
$time_prune_before = $localtimenow - $Settings->get('auto_prune_stats') * 86400;
// 1 day = 86400 seconds
// PRUNE HITLOG:
$hitlist_Timer->start('hitlog');
$hitlog_rows_affected = $DB->query("\n\t\t\tDELETE FROM T_hitlog\n\t\t\tWHERE hit_datetime < '" . date('Y-m-d', $time_prune_before) . "'", 'Autopruning hit log');
$hitlist_Timer->stop('hitlog');
$Debuglog->add('Hitlist::dbprune(): autopruned ' . $hitlog_rows_affected . ' rows from T_hitlog.', 'request');
// PREPARE PRUNING SESSIONS:
// Prune sessions that have timed out and are older than auto_prune_stats
$sess_prune_before = $localtimenow - $Settings->get('timeout_sessions');
// IMPORTANT: we cut off at the oldest date between session timeout and sessions pruning.
// So if session timeout is really long (2 years for example), the sessions table won't be pruned as small as expected from the pruning delay.
$smaller_time = min($sess_prune_before, $time_prune_before);
// allow plugins to prune session based data
$Plugins->trigger_event('BeforeSessionsDelete', $temp_array = array('cutoff_timestamp' => $smaller_time));
// PRUNE SESSIONS:
$hitlist_Timer->start('sessions');
$sessions_rows_affected = $DB->query('DELETE FROM T_sessions WHERE sess_lastseen_ts < ' . $DB->quote(date('Y-m-d H:i:s', $smaller_time)), 'Autoprune sessions');
$hitlist_Timer->stop('sessions');
$Debuglog->add('Hitlist::dbprune(): autopruned ' . $sessions_rows_affected . ' rows from T_sessions.', 'request');
// PRUNE BASEDOMAINS:
// Prune non-referrered basedomains (where the according hits got deleted)
// BUT only those with unknown dom_type/dom_status, because otherwise this
// info is useful when we get hit again.
$hitlist_Timer->start('basedomains');
$basedomains_rows_affected = $DB->query("\n\t\t\tDELETE T_basedomains\n\t\t\t FROM T_basedomains LEFT JOIN T_hitlog ON hit_referer_dom_ID = dom_ID\n\t\t\t WHERE hit_referer_dom_ID IS NULL\n\t\t\t AND dom_type = 'unknown'\n\t\t\t AND dom_status = 'unknown'");
$hitlist_Timer->stop('basedomains');
$Debuglog->add('Hitlist::dbprune(): autopruned ' . $basedomains_rows_affected . ' rows from T_basedomains.', 'request');
// OPTIMIZE TABLES:
$hitlist_Timer->start('optimize_hitlog');
$DB->query('OPTIMIZE TABLE T_hitlog');
$hitlist_Timer->stop('optimize_hitlog');
$hitlist_Timer->start('optimize_sessions');
$DB->query('OPTIMIZE TABLE T_sessions');
$hitlist_Timer->stop('optimize_sessions');
$hitlist_Timer->start('optimize_basedomains');
$DB->query('OPTIMIZE TABLE T_basedomains');
$hitlist_Timer->stop('optimize_basedomains');
// Stop total hitlist timer
$hitlist_Timer->stop('prune_hits');
$Settings->set('auto_prune_stats_done', date('Y-m-d H:i:s', $localtimenow));
// save exact datetime
$Settings->dbupdate();
$Messages->add(T_('The old hits & sessions have been pruned.'), 'success');
return array('result' => 'ok', 'message' => 'STATUS:' . "\n" . sprintf('T_hitlog: %s - %s rows', $tables[$db_config['aliases']['T_hitlog']]['type'], $tables[$db_config['aliases']['T_hitlog']]['rows']) . "\n" . sprintf('T_sessions: %s - %s rows', $tables[$db_config['aliases']['T_sessions']]['type'], $tables[$db_config['aliases']['T_sessions']]['rows']) . "\n" . sprintf('T_basedomains: %s - %s rows', $tables[$db_config['aliases']['T_basedomains']]['type'], $tables[$db_config['aliases']['T_basedomains']]['rows']) . "\n" . "\n" . 'PRUNING:' . "\n" . sprintf('%s rows from T_hitlog, Execution time: %s seconds', $hitlog_rows_affected, $hitlist_Timer->get_duration('hitlog')) . "\n" . sprintf('%s rows from T_sessions, Execution time: %s seconds', $sessions_rows_affected, $hitlist_Timer->get_duration('sessions')) . "\n" . sprintf('%s rows from T_basedomains, Execution time: %s seconds', $basedomains_rows_affected, $hitlist_Timer->get_duration('basedomains')) . "\n" . "\n" . 'OPTIMIZING:' . "\n" . sprintf('T_hitlog: %s seconds', $hitlist_Timer->get_duration('optimize_hitlog')) . "\n" . sprintf('T_sessions: %s seconds', $hitlist_Timer->get_duration('optimize_sessions')) . "\n" . sprintf('T_basedomains: %s seconds', $hitlist_Timer->get_duration('optimize_basedomains')) . "\n" . "\n" . sprintf('Total execution time: %s seconds', $hitlist_Timer->get_duration('prune_hits')));
}
示例2: dbm_analyze_tables
/**
* Analyze DB tables
*
* @param boolean Display messages
* @param boolean TRUE - to make optimize query for each table separately
* @return array Results of the mysql command 'ANALYZE'
*/
function dbm_analyze_tables($display_messages = true, $separate_tables = true)
{
global $DB, $tableprefix, $dbm_tables_count;
load_class('_core/model/_timer.class.php', 'Timer');
$Timer = new Timer('dbm_analyze');
// Get all table names from DB
$tables = $DB->get_results('SHOW TABLE STATUS FROM `' . $DB->dbname . '` LIKE \'' . $tableprefix . '%\'');
$tables_names = array();
foreach ($tables as $table) {
$tables_names[] = $table->Name;
}
$dbm_tables_count = count($tables_names);
if ($display_messages) {
// Display messages
echo '<b>' . T_('Analyze tables...') . '</b><br />';
evo_flush();
}
$Timer->start('analyze_tables');
if ($separate_tables) {
// Analyze each table in separate query
$analyze_results = array();
foreach ($tables_names as $table) {
$Timer->start('analyze_one_table');
$table_results = $DB->get_results('ANALYZE NO_WRITE_TO_BINLOG TABLE ' . $table);
$Timer->stop('analyze_one_table');
if ($display_messages) {
// Display messages
dbm_display_result_messages($table_results, 'analyze');
echo '<b>' . sprintf(T_('Time: %s seconds'), $Timer->get_duration('analyze_one_table')) . '</b><br /><br />';
}
evo_flush();
$analyze_results = array_merge($analyze_results, $table_results);
}
} else {
// Analyze all table by one query, Used for cron job
$analyze_results = $DB->get_results('ANALYZE NO_WRITE_TO_BINLOG TABLE ' . implode(', ', $tables_names));
}
$Timer->stop('analyze_tables');
if ($display_messages) {
// Display messages
if (!$separate_tables) {
// Display full report log for case when the tables were analyzed by one query
dbm_display_result_messages($analyze_results, 'analyze');
}
echo '<b>' . sprintf(T_('Full execution time: %s seconds'), $Timer->get_duration('analyze_tables')) . '</b>';
}
return $analyze_results;
}
示例3:
$timer->start('test timer');
// Стартуем таймер
$timer->pause_off('test timer');
// Игнорируем - небыло паузы
sleep(1);
// Это время было бы засчитано, но в следующей строке сброс
$timer->start('test timer');
// Стартуем таймер заново, значение снова ноль
$timer->pause_on('test timer');
// Ставим таймер на паузу
$timer->pause_off('test timer');
// Снимаем таймер с паузы
sleep(1);
// Это время будет засчитано
$timer->pause_on('test timer');
// Ставим таймер на паузу
sleep(1);
// Это время -= НЕ =- будет засчитано
$timer->pause_on('test timer');
// Игнорируем - уже стоит на паузе
$timer->pause_off('test timer');
// Снимаем таймер с паузы
sleep(1);
// Это время будет засчитано
$timer->stop('test timer');
echo $timer->get_duration('test timer') . ' секунд' . "\n";
?>
</pre>
</body>
</html>