function printGenerationTime() { $debug_time["end"] = getmicrotime(); if ($debug) { echo "Page générée en " . round($debug_time["end"] - $debug_time["start"], 3) . " secondes"; } }
function safe_query($q = '', $debug = '', $unbuf = '') { global $DB, $txpcfg, $qcount, $qtime, $production_status; $method = !$unbuf ? 'mysql_query' : 'mysql_unbuffered_query'; if (!$q) { return false; } if ($debug or TXP_DEBUG === 1) { dmp($q); dmp(mysql_error()); // dmp(debug_backtrace()); } $start = getmicrotime(); $result = $method($q, $DB->link); $time = sprintf('%02.6f', getmicrotime() - $start); @($qtime += $time); @$qcount++; if ($result === false and (@$production_status == 'debug' or @$production_status == 'test')) { trigger_error(mysql_error() . n . $q, E_USER_ERROR); } trace_add("[SQL ({$time}): {$q}]"); if (!$result) { return false; } return $result; }
function DoBenchmark() { if (PHP_VERSION < 4.1) { global $HTTP_GET_VARS; $_GET = $HTTP_GET_VARS; } $ITER = isset($_GET['iter']) ? (int) $_GET['iter'] : 1000; $SWAP = function_exists('bench2') && !empty($_GET['swap']); if ($ITER > 10000) { die("DOS attack?"); } flush(); $t1 = getmicrotime(); for ($i = $ITER; --$i >= 0;) { _bench1(); } $overhead = getmicrotime() - $t1; //printf("oh=%8.6f ",$overhead); if ($SWAP) { $time2 = dobench2($ITER) - $overhead; } else { $time1 = dobench1($ITER) - $overhead; } if (function_exists('bench2')) { if ($SWAP) { $time1 = dobench1($ITER) - $overhead; } else { $time2 = dobench2($ITER) - $overhead; } printf("##%8.4f##%8.4f##", abs($time1) * (1000.0 / $ITER), abs($time2) * (1000.0 / $ITER)); } else { printf("##%8.4f##", $time1); } }
/** * Ending measurement * * Ending measurement of time for specified block * * @param string $mpoint monitoring block name */ function EndMeasure($mpoint, $save_to_db = 0) { global $perf_data; if (!$perf_data[$mpoint]['START']) { return; } $perf_data[$mpoint]['END'] = getmicrotime(); if (!$perf_data[$mpoint]['MEMORY_END'] && function_exists('memory_get_usage')) { $perf_data[$mpoint]['MEMORY_END'] = memory_get_usage(); } $perf_data[$mpoint]['TIME'] += $perf_data[$mpoint]['END'] - $perf_data[$mpoint]['START']; $perf_data[$mpoint]['NUM']++; return; if ($save_to_db) { global $db; if ($db->dbh) { $rec = array(); $rec['OPERATION'] = substr($mpoint, 0, 200); $rec['COUNTER'] = 1; $rec['TIMEUSED'] = $perf_data[$mpoint]['TIME']; $rec['ADDED'] = date('Y-m-d H:i:s'); if ($_SERVER['REQUEST_URI']) { $rec['SOURCE'] = 'web'; } else { $rec['SOURCE'] = 'cmd'; } SQLInsert('performance_log', $rec); } } }
function SaveHTTPFile($fFileHTTPPath, $fFileSavePath, $fFileSaveName) { //记录程序开始的时间 $BeginTime = getmicrotime(); //取得文件名 $fFileSaveName = $fFileSavePath . "/" . $fFileSaveName; make_dir(dirname($fFileSaveName)); //取得文件的内容 ob_start(); readfile($fFileHTTPPath); $img = ob_get_contents(); ob_end_clean(); //$size = strlen($img); //保存到本地 $fp2 = @fopen($fFileSaveName, "a"); fwrite($fp2, $img); fclose($fp2); /*加水印代码*/ require_once ROOT_PATH . 'includes/cls_image.php'; $ext = get_extension($fFileSaveName); $fFileSaveName = convert_GIF_to_JPG($fFileSaveName); if (CopyFiles($fFileSaveName)) { $image = new cls_image(); $image->add_watermark($fFileSaveName, '', '../../../../' . $GLOBALS['waterMark']['watermark'], $GLOBALS['waterMark']['watermark_place'], $GLOBALS['waterMark']['watermark_alpha']); } if ($ext == 'gif' || $ext == '.gif') { back_JPG_to_GIF($fFileSaveName); } /*加水印代码--end*/ //记录程序运行结束的时间 $EndTime = getmicrotime(); //返回运行时间 return $EndTime - $BeginTime; }
function safe_query($q = '', $debug = '', $unbuf = '') { global $DB, $txpcfg, $qcount, $qtime, $production_status; $method = !$unbuf ? 'mysql_query' : 'mysql_unbuffered_query'; if (!$q) { return false; } if ($debug or TXP_DEBUG === 1) { dmp($q); } $start = getmicrotime(); $result = $method($q, $DB->link); $time = sprintf('%02.6f', getmicrotime() - $start); @($qtime += $time); @$qcount++; if ($result === false and (txpinterface === 'admin' or @$production_status == 'debug' or @$production_status == 'testing')) { $caller = $production_status == 'debug' ? n . join("\n", get_caller()) : ''; trigger_error(mysql_error() . n . $q . $caller, E_USER_WARNING); } trace_add("[SQL ({$time}): {$q}]"); if (!$result) { return false; } return $result; }
function set_profiling() { if (USE_PROFILING) { global $start_exec_time; $start_exec_time = getmicrotime(); } }
function get_physical_dmg_multiplier(&$pa, &$pd, $active) { if (eval(__MAGIC__)) { return $___RET_VALUE; } $r = array(); if (\skillbase\skill_query(262, $pa) && check_unlocked262($pa) && $pa['user_commanded'] == 1 && $active && !$pa['is_counter'] && (!isset($pa['sk262flag']) || !$pa['sk262flag'])) { eval(import_module('logger')); $ct = floor(getmicrotime() * 1000); $st = (int) \skillbase\skill_getvalue(262, 'ct', $pa); $t = $ct - $st; //$log.='t='.$t; $pretime = skill262_get_pretime($pa); $dmgperc = skill262_get_dmgperc($pa); $maxdmgperc = skill262_get_maxdmgperc($pa); //$log.=' pretime='.$pretime.' dmgperc='.$dmgperc.' maxdmgperc='.$maxdmgperc; if ($t < $pretime) { $z = 0; } else { $z = ($t - $pretime) / 1000 * $dmgperc; $z = min($z, $maxdmgperc); $z = round($z); $log .= '<span class="lime">你积蓄力量打出了致命的一拳!伤害增加了' . $z . '%!</span><br>'; } $r = array(1 + $z / 100); } return array_merge($r, $chprocess($pa, $pd, $active)); }
function getEndTimer() { global $time_start_tmp; $t = sprintf("%.2f", getmicrotime() - $time_start_tmp); $t = str_replace(",", ".", $t); return $t; }
/** * @return bool */ function Connect() { if (!extension_loaded('odbc')) { $this->ErrorDesc = 'Can\'t load ODBC extension.'; setGlobalError($this->ErrorDesc); $this->_log->WriteLine($this->ErrorDesc, LOG_LEVEL_ERROR); return false; } if ($this->_log->Enabled) { $ti = getmicrotime(); } $this->_conectionHandle = @odbc_connect($this->_dbCustomConnectionString, $this->_user, $this->_pass, SQL_CUR_USE_ODBC); if ($this->_conectionHandle && $this->_log->Enabled) { $this->_log->WriteLine(':: connection time -> ' . (getmicrotime() - $ti)); } if ($this->_conectionHandle) { if ($this->_dbType == DB_MYSQL) { @odbc_exec($this->_conectionHandle, 'SET NAMES utf8'); } return true; } else { $this->_setSqlError(); return false; } }
/** * @return bool */ function Connect() { //if ($this->_conectionHandle != false) return true; if (!extension_loaded('mssql')) { $this->ErrorDesc = 'Can\'t load MsSQL extension.'; setGlobalError($this->ErrorDesc); $this->_log->WriteLine($this->ErrorDesc, LOG_LEVEL_ERROR); return false; } if ($this->_log->Enabled) { $ti = getmicrotime(); } $this->_conectionHandle = @mssql_connect($this->_host, $this->_user, $this->_password); if ($this->_conectionHandle && $this->_log->Enabled) { $this->_log->WriteLine(':: connection time -> ' . (getmicrotime() - $ti)); } if ($this->_conectionHandle) { if (strlen($this->_dbName) > 0) { $dbselect = @mssql_select_db($this->_dbName, $this->_conectionHandle); if (!$dbselect) { $this->_setSqlError(); $this->_conectionHandle = $dbselect; @mssql_close($this->_conectionHandle); return false; } } return true; } else { $this->_setSqlError(); return false; } }
function debug_output() { global $settings__time_debugging_enabled, $settings__query_debugging_enabled, $debug__script_started; global $debug__query_array, $debug__query_time; if (isset($settings__time_debugging_enabled) && $settings__time_debugging_enabled == 'y') { if (isset($debug__script_started)) { $debug__script_stopped = getmicrotime(); $time_needed = round(($debug__script_stopped - getmicrotime($debug__script_started)) * 1000, 3); echo 'Overall query time: ' . round($debug__query_time * 1000, 3) . 'msec,<br> Overall script time: ' . $time_needed . 'msec<BR><BR>'; } else { echo 'No script start time found.<BR><BR>'; } } if (isset($settings__query_debugging_enabled) && $settings__query_debugging_enabled == 'y') { $i = 0; if (isset($debug__query_array)) { echo 'Nb of queries: ' . count($debug__query_array) . '<BR> <table border=0>'; foreach ($debug__query_array as $query) { $i++; echo '<tr><td valign="top"><B>' . $i . '.</b></td><td valign="top">' . round($query['time'] * 1000, 3) . 'msec </td><td>' . str_replace(array("\n", ","), array("<br />", ", "), $query['query']) . '</td></tr>'; } echo '</table>'; } } }
public static function getExpressionOptions($_expression, $_options) { $startLoadTime = getmicrotime(); $cmd = cmd::byId(str_replace('#', '', cmd::humanReadableToCmd($_expression))); if (is_object($cmd)) { $return['html'] = trim($cmd->toHtml('scenario', $_options)); } else { try { $return['html'] = getTemplate('core', 'scenario', $_expression . '.default'); if (is_json($_options)) { $_options = json_decode($_options, true); } if (is_array($_options) && count($_options) > 0) { foreach ($_options as $key => $value) { $replace['#' . $key . '#'] = $value; } } if (!isset($replace['#id#'])) { $replace['#id#'] = rand(); } $return['html'] = template_replace(cmd::cmdToHumanReadable($replace), $return['html']); } catch (Exception $e) { } } $replace = array('#uid#' => 'exp' . mt_rand()); $return['html'] = translate::exec(template_replace($replace, $return['html']), 'core/template/scenario/' . $_expression . '.default'); return $return; }
/** * Element * * Lets you determine whether an array index is set and whether it has a value. * If the element is empty it returns NULL (or whatever you specify as the default value.) * * @param string * @param array * @param mixed * @return mixed depends on what the array contains */ function querydb($query, $reply = 1, $CALLED_FUNCTION = "_common") { /* Get function My sql query */ global $mysql, $MySQLi; //$query = @mysql_escape_string($query); 'not efective while using id_xx='xxxxx'.. will esacepe 'xxxxx' to \'xxxxx\' global $time_start, $pre_src, $pre_rpc, $pre_src2, $pre_rpc2; //mysql_set_charset('utf8'); $MySQLi->query('SET NAMES utf8'); $MySQLi->query('SET CHARACTER SET utf8'); //HTML format for query //$print_query = preg_replace($pre_src2,$pre_rpc2,$query); $print_query = preg_replace($pre_src, $pre_rpc, $query); if (GLOBAL_DISPLAY_MYSQL_QUERY == 1) { // MENCETAL waktu eksekusi erserta eksekusi scriptnya //global $_SERVER; //$self = $_SERVER['PHP_SELF']; $time_end = getmicrotime(); $time_query = $time_end - $time_start; print "<div class=\"php_note\">" . sprintf("%6.5f", $time_query) . " (s)  > MySQL Query <b>{$CALLED_FUNCTION}</b> : <icode class='fsi'>{$print_query};</icode></div>"; } if ($result = $MySQLi->query($query)) { //-> WARNING! this function is DEPRECATED, see PHP Manual.chm return $result; } else { if ($reply == 1 && GLOBAL_DISPLAY_ERRORS == 1) { print "<div class=\"php_on_error\">Failed For Operand a Query = " . $print_query . ", <b>" . $MySQLi->error . "</b></div>"; } } }
function process_all_maps($dir, $rootLevel, $prefixRemoveCharsArg) { set_time_limit(160); $i = 0; if ($rootLevel) { $prefixRemoveChars = strlen(trim($dir, "/")) + 1; } else { $prefixRemoveChars = $prefixRemoveCharsArg; } $current_dir = opendir($dir); while ($entryname = readdir($current_dir)) { if (is_dir("{$dir}/{$entryname}") && $entryname != "." && $entryname != "..") { // echo "<br>$dir/$entryname<br>"; process_all_maps($dir . "/" . $entryname, 0, $prefixRemoveChars); } else { if ($entryname != "." && $entryname != ".." && strtolower(substr($entryname, -4)) == ".sid") { $filename = substr("{$dir}/{$entryname}", 0, -4); echo "PROCESSING: {$filename}\n"; // Time the execution $tstart = getmicrotime(); processMap($filename); $tend = getmicrotime(); $totaltime = $tend - $tstart; echo "{$totaltime} secs\n"; flush(); } } } closedir($current_dir); }
public static function getExecutionTime() { if (!self::$startTime) { return 0; } else { return getmicrotime() - self::$startTime; } }
function timer_end($name) { $mt = getmicrotime(); $md5 = md5($name); if (!isset($GLOBALS['timers'][$md5]['start_time'])) { return; } $GLOBALS['timers'][$md5] = array('name' => $name, 'time' => $mt - $GLOBALS['timers'][$md5]['start_time']); }
function debug($msg, $level = 0) { if ($level < $GLOBALS['g_debug_level']) { return; } $GLOBALS['g_debug_log'][$GLOBALS['g_debug_count']]['msg'] = $msg; $GLOBALS['g_debug_log'][$GLOBALS['g_debug_count']]['time'] = getmicrotime(); $GLOBALS['g_debug_count']++; }
/** * Ending measurement * * Ending measurement of time for specified block * * @param string $mpoint monitoring block name */ function EndMeasure($mpoint) { global $perf_data; $perf_data[$mpoint]['END']=getmicrotime(); if(!$perf_data[$mpoint]['MEMORY_END'] && function_exists('memory_get_usage')) { $perf_data[$mpoint]['MEMORY_END']=memory_get_usage(); } $perf_data[$mpoint]['TIME']+=$perf_data[$mpoint]['END']-$perf_data[$mpoint]['START']; $perf_data[$mpoint]['NUM']++; }
function pagetime($type) { static $orig_time; if ($type == 'init') { $orig_time = getmicrotime(); } if ($type == 'print') { printf('%2.4f', getmicrotime() - $orig_time); } }
function tac() { global $debug; if ($debug) { global $gl_depth, $gl_time, $gl_count, $gl_names; $name = $gl_names[$gl_depth]; log_write(getmicrotime() - $gl_time[$gl_depth], $gl_names[$gl_depth], $gl_count[$name], $gl_depth); $gl_depth--; } }
protected function _ConstructPostData($postData) { $currency = GetDefaultCurrency(); $currencycode = strtolower($currency['currencycode']); switch ($postData['cctype']) { case 'VISA': $cctype = '001'; break; case 'MC': $cctype = '002'; break; case 'AMEX': $cctype = '003'; break; case 'DISCOVER': $cctype = '004'; break; case 'DINERS': $cctype = '005'; break; default: $cctype = '000'; break; } $amount = $this->GetGatewayAmount(); $billingDetails = $this->GetBillingDetails(); $timestamp = getmicrotime(); $transactionid = $this->GetCombinedOrderId(); $signatureData = getMerchantID() . $amount . $currencycode . $timestamp . 'sale'; $cybersourcePost['merchantID'] = getMerchantID(); $cybersourcePost['billTo_firstName'] = htmlentities($billingDetails['ordbillfirstname']); $cybersourcePost['billTo_lastName'] = $billingDetails['ordbilllastname']; $cybersourcePost['billTo_street1'] = $billingDetails['ordbillstreet1']; $cybersourcePost['billTo_city'] = $billingDetails['ordbillsuburb']; $cybersourcePost['billTo_state'] = $billingDetails['ordbillstate']; $cybersourcePost['billTo_postalCode'] = $billingDetails['ordbillzip']; $cybersourcePost['billTo_country'] = $billingDetails['ordbillcountry']; $cybersourcePost['billTo_email'] = $billingDetails['ordbillemail']; $cybersourcePost['card_cardType'] = $cctype; $cybersourcePost['card_accountNumber'] = $postData['ccno']; $cybersourcePost['card_expirationMonth'] = $postData['ccexpm']; $cybersourcePost['card_expirationYear'] = '20' . $postData['ccexpy']; $cybersourcePost['orderPage_timestamp'] = $timestamp; $cybersourcePost['orderPage_signaturePublic'] = hopHash($signatureData, getPublicKey()); $cybersourcePost['orderPage_serialNumber'] = getSerialNumber(); $cybersourcePost['orderPage_version'] = '4'; $cybersourcePost['orderPage_transactionType'] = 'sale'; $cybersourcePost['amount'] = $amount; $cybersourcePost['currency'] = $currencycode; $cybersourcePost['hash'] = md5($this->GetValue("accessid") . $transactionid . $_COOKIE['SHOP_ORDER_TOKEN'] . $amount); $cybersourcePost['orderid'] = $transactionid; $cybersourcePost['iscsessionid'] = $_COOKIE['SHOP_ORDER_TOKEN']; return $cybersourcePost; }
function debug_timestamp($comment = false, $extra = null) { global $timestamp_last, $timestamp_start; $t = getmicrotime(); if ($comment) { printf("<!--\n %s\n %f seconds since start\n %f seconds since last\n-->", is_null($extra) ? 'TIMESTAMP' : $extra, $t - $timestamp_start, $t - $timestamp_last); } else { debug("TIMESTAMP", sprintf("%f seconds since start; %f seconds since last", $t - $timestamp_start, $t - $timestamp_last)); } $timestamp_last = $t; }
function PrintTimestamp() { global $STARTTIME, $LASTTIME, $TIMESTAMPCOUNT; $now = getmicrotime(false); echo "\n\n<!-- [TIME] "; echo "Elapsed: ".number_format($now-$STARTTIME,4); echo " Delta: ".number_format($now-$LASTTIME, 6); echo " Now: ".$now; echo " Instance: ".$TIMESTAMPCOUNT++; echo " -->\n\n"; $LASTTIME = $now; }
function handle_event($location, $baseLink = false, $needHeader = false) { if ($baseLink === false) { global $PHP_SELF; $baseLink = substr($PHP_SELF, strrpos($PHP_SELF, "/") + 1) . "?"; } else { //debug("Base link was specified as $baseLink"); //debug(debug_backtrace()); } global $session, $playermount, $badguy; $skipdesc = false; tlschema("events"); $allowinactive = false; $eventhandler = httpget('eventhandler'); if ($session['user']['superuser'] & SU_DEVELOPER && $eventhandler != "") { $allowinactive = true; $array = preg_split("/[:-]/", $eventhandler); if ($array[0] == "module") { $session['user']['specialinc'] = "module:" . $array[1]; } else { $session['user']['specialinc'] = ""; } } $_POST['i_am_a_hack'] = 'true'; if ($session['user']['specialinc'] != "") { $specialinc = $session['user']['specialinc']; $session['user']['specialinc'] = ""; if ($needHeader !== false) { page_header($needHeader); } output("`^`c`bSomething Special!`c`b`0"); if (strchr($specialinc, ":")) { $array = split(":", $specialinc); $starttime = getmicrotime(); module_do_event($location, $array[1], $allowinactive, $baseLink); $endtime = getmicrotime(); if ($endtime - $starttime >= 1.0 && $session['user']['superuser'] & SU_DEBUG_OUTPUT) { debug("Slow Event (" . round($endtime - $starttime, 2) . "s): {$hookname} - {$row['modulename']}`n"); } } if (checknavs()) { // The page rendered some linkage, so we just want to exit. page_footer(); } else { $skipdesc = true; $session['user']['specialinc'] = ""; $session['user']['specialmisc'] = ""; httpset("op", ""); } } tlschema(); return $skipdesc; }
function go($math_wrapper) { echo "Test {$math_wrapper}: "; mt_srand(1); $start = getmicrotime(); $keypair =& Crypt_RSA_KeyPair::factory(KEY_LENGTH, $math_wrapper, '', 'mt_rand'); if (PEAR::isError($obj)) { echo 'failed: ', $obj->getMessage(), "\n"; return; } $time = getmicrotime() - $start; printf("done. Time: %.3f seconds\n", $time); }
/** * @param string $query * @return mixed */ function Execute($query) { $this->_log->WriteLine('SQL Query: ' . $query); $ti = getmicrotime(); $this->_resultId = @odbc_exec($this->_conectionHandle, $query); $this->_log->WriteLine('>> Execute TIME - ' . (getmicrotime() - $ti) . ' :: result: ' . (bool) $this->_resultId); if ($this->_resultId) { return $this->_resultId !== false; } else { $this->_setSqlError(); return false; } }
function speedAnalyzer($name = '', $start = false) { global $speedAnalyze, $speedAnalyzeLast; $current = getmicrotime(); if (!$start) { $start = $speedAnalyze; } $diff = round(($current - $start) * 1000); $result = array('<-' . ($diff - $speedAnalyzeLast), $name, $current, $current - $start, $diff); $speedAnalyzeLast = $diff; //file_put_contents(CONTROLLER_PATH.'xamp.log', join("\t", $result)."\n", FILE_APPEND); return $result; }
function output() { global $db, $php_start, $main, $vars; if ($this->hide) { return; } $this->tpl['php_time'] = getmicrotime() - $php_start; $this->tpl['mysql_time'] = $db->total_time; if (isset($main->userdata->privileges['admin']) && $main->userdata->privileges['admin'] === TRUE && $vars['debug']['enabled'] == TRUE) { $this->tpl['debug_mysql'] = ROOT_PATH . "debug/mysql.php?" . get_qs(); } return template($this->tpl, __FILE__); }