function sql_query($query) { global $_auth, $_SQLUser, $_SQLArray, $_SQLCount, $_SQLTime, $_SQLCalc, $_SQLLog, $_SQLLastQuery; if ($_SQLCalc) { $time_start = gettimeofday(); } $_SQLLastQuery = $query; $result = mysql_query($query) or fatal_error(mysql_error()); if ($_SQLCalc) { $time_end = gettimeofday(); $secdiff = $time_end["sec"] - $time_start["sec"]; $usecdiff = $time_end["usec"] - $time_start["usec"]; $timeF = ($secdiff * 1000000 + $usecdiff) / 1000000; $_SQLCount++; $_SQLTime += $timeF; } if ($_SQLLog) { if (preg_match('/^SELECT\\sCOUNT\\(\\*\\)\\sFROM/', $query)) { $numRows = is_resource($result) ? "=" . mysql_result($result, 0) : "-"; } else { $numRows = is_resource($result) ? mysql_num_rows($result) : "-"; } while (strlen($numRows) < 5) { $numRows = " " . $numRows; } $_SQLArray[] = array("time" => $timeF, "rows" => $numRows, "query" => $query); } return $result; }
public function setUp() { parent::setUp(); // Setup container names array (list of container names used by // integration tests) self::$testQueues = array(); for ($i = 0; $i < 10; $i++) { self::$testQueues[$i] = self::$testQueuesPrefix . round(gettimeofday(true)) . ($i + 1); } self::$creatableQueues = array(); for ($i = 0; $i < 3; $i++) { self::$creatableQueues[$i] = self::$createableQueuesPrefix . ($i + 1); } self::$TEST_QUEUE_FOR_MESSAGES = self::$testQueues[0]; self::$TEST_QUEUE_FOR_MESSAGES_2 = self::$testQueues[1]; self::$TEST_QUEUE_FOR_MESSAGES_3 = self::$testQueues[2]; self::$TEST_QUEUE_FOR_MESSAGES_4 = self::$testQueues[3]; self::$TEST_QUEUE_FOR_MESSAGES_5 = self::$testQueues[4]; self::$TEST_QUEUE_FOR_MESSAGES_6 = self::$testQueues[5]; self::$TEST_QUEUE_FOR_MESSAGES_7 = self::$testQueues[6]; self::$TEST_QUEUE_FOR_MESSAGES_8 = self::$testQueues[7]; self::$CREATABLE_QUEUE_1 = self::$creatableQueues[0]; self::$CREATABLE_QUEUE_2 = self::$creatableQueues[1]; self::$CREATABLE_QUEUE_3 = self::$creatableQueues[2]; // Create all test containers and their content self::createQueues(self::$testQueuesPrefix, self::$testQueues); }
function get_secs() { global $start_secs; $arr = gettimeofday(); $now = $arr['sec'] + $arr['usec'] / 1000000.0; return $now - $start_secs; }
/** \sa http://php.net/manual/en/function.gettimeofday.php \sa http://php.net/manual/en/function.microtime.php */ function utime($t = NULL) { if (is_null($t)) { $t = gettimeofday(false); } return sprintf('%d.%06d', $t['sec'], $t['usec']); }
function ListByDate($timespan = 1209600) { require 'mysql.php'; $all = mysql_query("SELECT title, filename, UNIX_TIMESTAMP(ultime), description, dir FROM descriptions ORDER BY `ultime` DESC, `filename` ASC"); mysql_close($con); $TWO_WEEKS = 1209600; $SPAN = 1.5 * $TWO_WEEKS; $time = gettimeofday(); $currentTime = (int) $time[sec]; $n = 0; while ($row = mysql_fetch_array($all)) { $ultime = (int) $row['UNIX_TIMESTAMP(ultime)']; //echo 'Current Time = '.$currentTime.' seconds'; $elapsedTime = $currentTime - $ultime; //echo 'Elapsed Time = '.$elapsedTime.' seconds'; if ($elapsedTime < $SPAN) { $newShiurim['title'][$n] = $row['title']; $newShiurim['filename'][$n] = $row['filename']; $newShiurim['dir'][$n] = $row['dir']; $newShiurim['date'][$n] = $ultime; $newShiurim['description'][$n] = $row['description']; $n++; } } $sharedDate = $newShiurim['date'][0]; printHeadline('New classes uploaded on ' . date("l F j, Y", $sharedDate)); for ($i = 0; $i < sizeof($newShiurim['dir']); $i++) { if ($newShiurim['date'][$i] != $sharedDate) { $sharedDate = $newShiurim['date'][$i]; printNewHeadline('New classes uploaded on ' . date("l F j, Y", $sharedDate)); } printShiur($newShiurim['title'][$i], $newShiurim['filename'][$i], $newShiurim['description'][$i], $newShiurim['dir'][$i]); } //echo '<br />'; }
function Draw() { $barCount = 6; $t = (gettimeofday(true) - $this->startTime) * 1000; $this->Clear(); $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK); for ($i = 0; $i < $barCount; $i++) { $v = (sin($t / 500.0 + 1.0 * $i / $barCount) + 1) / 2 * $this->getHeight(); $p1_x = 0; $p1_y = intval($v); $p2_x = $this->getWidth() - 1; $p2_y = intval($v); $this->setColorAnsi($i + 9, AnsiColor::BLACK); /* drawLine is already clipped, we don't care about overflows */ $this->drawLine($p1_x + 0, $p1_y - 2, $p2_x + 0, $p2_y - 2, ord('-')); $this->drawLine($p1_x + 0, $p1_y - 1, $p2_x + 0, $p2_y - 1, ord('*')); $this->drawLine($p1_x, $p1_y, $p2_x, $p2_y, ord('#')); $this->drawLine($p1_x + 0, $p1_y + 1, $p2_x + 0, $p2_y + 1, ord('*')); $this->drawLine($p1_x + 0, $p1_y + 2, $p2_x + 0, $p2_y + 2, ord('-')); } $w = $this->getWidth(); $h = $this->getHeight(); $x = intval($t / 10 % (12 * $w)); $y = intval($h * (2.0 + sin($t / 200.0)) / 4); $this->d->bitmap($this, -$x, $h / 2 - $y, $w * 12, $y * 2); $this->d->bitmap($this, 12 * $w - $x, $h / 2 - $y, $w * 12, $y * 2); $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLUE); $this->putStr($this->getWidth() - 30, $this->getHeight() - 2, " -=[ Powered by libcaca ]=- "); $this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK); }
function generateMtid() { $time = gettimeofday(); $mtid = $time['sec']; $mtid .= $time['usec']; return $mtid; }
public function debugHelper() { echo "<pre>"; echo "<b>Kajona V4 Debug Subsystem</b>\n\n"; if (getGet("debugfile") != "") { echo "Loading path for " . getGet("debugfile") . "\n"; $strPath = array_search(getGet("debugfile"), class_resourceloader::getInstance()->getFolderContent("/debug", array(".php"))); if ($strPath !== false) { echo "Passing request to " . $strPath . "\n\n"; include _realpath_ . $strPath; } } else { echo "Searching for debug-scripts available...\n"; $arrFiles = class_resourceloader::getInstance()->getFolderContent("/debug", array(".php")); echo "<ul>"; foreach ($arrFiles as $strPath => $strOneFile) { echo "<li><a href='?debugfile=" . $strOneFile . "' >" . $strOneFile . "</a> <br />" . $strPath . "</li>"; } echo "</ul>"; } $arrTimestampEnde = gettimeofday(); $intTimeUsed = ($arrTimestampEnde['sec'] * 1000000 + $arrTimestampEnde['usec'] - ($this->arrTimestampStart['sec'] * 1000000 + $this->arrTimestampStart['usec'])) / 1000000; echo "\n\n<b>PHP-Time:</b> " . number_format($intTimeUsed, 6) . " sec \n"; echo "<b>Queries db/cachesize/cached/fired:</b> " . class_carrier::getInstance()->getObjDB()->getNumber() . "/" . class_carrier::getInstance()->getObjDB()->getCacheSize() . "/" . class_carrier::getInstance()->getObjDB()->getNumberCache() . "/" . (class_carrier::getInstance()->getObjDB()->getNumber() - class_carrier::getInstance()->getObjDB()->getNumberCache()) . "\n"; echo "<b>Templates cached:</b> " . class_carrier::getInstance()->getObjTemplate()->getNumberCacheSize() . " \n"; echo "<b>Memory/Max Memory:</b> " . bytesToString(memory_get_usage()) . "/" . bytesToString(memory_get_peak_usage()) . " \n"; echo "<b>Classes Loaded:</b> " . class_classloader::getInstance()->getIntNumberOfClassesLoaded() . " \n"; echo "<b>Cache requests/hits/saves/cachesize:</b> " . class_cache::getIntRequests() . "/" . class_cache::getIntHits() . "/" . class_cache::getIntSaves() . "/" . class_cache::getIntCachesize() . " \n"; echo "</pre>"; }
/** * Init function * @ingroup Core */ function xanth_init() { global $start_time; $start_time = gettimeofday(TRUE); ob_start(); xanth_db_query_reset_count(); set_error_handler('xanth_php_error_handler'); xanth_db_connect(xanth_conf_get('db_host', ''), xanth_conf_get('db_name', ''), xanth_conf_get('db_user', ''), xanth_conf_get('db_pass', ''), xanth_conf_get('db_port', '')); session_set_save_handler("on_session_start", "on_session_end", "on_session_read", "on_session_write", "on_session_destroy", "on_session_gc"); session_start(); xComponent::init_all(); xModule::init_all(); //xTheme::find_default()->init(); xanth_invoke_multi_hook(MULTI_HOOK_PAGE_CREATE_EVT, NULL); xanth_invoke_mono_hook(MONO_HOOK_PAGE_CREATE, NULL); //print log echo '<br />'; echo '<br />'; echo '<br />'; echo '<br />'; echo '<br />'; foreach (xanth_get_screen_log() as $entry) { echo '<br />' . $entry->level . ' ' . $entry->component . ' ' . $entry->message . ' ' . $entry->filename . '@' . $entry->line; } session_write_close(); echo ob_get_clean(); }
public function getCache($key) { if ($this->_checkKeyMisses($key)) { return null; } if (is_array($this->_local_cache) && isset($this->_local_cache[$key])) { $cache = $this->_local_cache[$key]; if ($cache != null) { return $cache; } } //$cache = Globals::getCache(); $cache = $this->_memcache; $origin_key = $key; $starttime = gettimeofday(true); $result = $cache->load($key); $endtime = gettimeofday(true); if ($result === FALSE) { $this->_addKeyMisses($origin_key); } if ($this->_profiler_enable) { $this->_profiler->pushToCacheProfiler($origin_key, $result, $starttime, $endtime); } if ($result != null) { $this->syncache($key, $result); $result = json_decode($result, true); } $this->_local_cache[$key] = $result; return $result; }
/** * sleeps some number of microseconds * * @param string $usec the number of microseconds to sleep * @access public * @deprecated */ function usleepWindows($usec) { $start = gettimeofday(); do { $stop = gettimeofday(); $timePassed = 1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec']; } while ($timePassed < $usec); }
function AddToEmailLog($sMessage, $iUserID) { $tSystem = gettimeofday(); $tSec = $tSystem['sec']; $tUsec = str_pad($tSystem['usec'], 6, '0'); $sSQL = "INSERT INTO email_job_log_{$iUserID} " . "SET ejl_text='" . mysql_real_escape_string($sMessage) . "', " . " ejl_time='{$tSec}', " . " ejl_usec='{$tUsec}'"; RunQuery($sSQL); }
function session_regenerate_id() { $tv = gettimeofday(); $buf = sprintf("%.15s%ld%ld%0.8f", $_SERVER['REMOTE_ADDR'], $tv['sec'], $tv['usec'], php_combined_lcg() * 10); session_id(md5($buf)); setcookie('PHPSESSID', session_id(), NULL, '/'); return TRUE; }
protected function _genAppid() { $time = gettimeofday(); $time = $time['sec'] * 100 + $time['usec']; $rand = mt_rand(1, $time + $time); $id = ($time ^ $rand) & 0xffffffff; return floor($id / 100) * 100; }
/** * Create a hash with a timeout from a config setting based on * the $name, with a salt from timeofday. The salt probably * doesn't matter much, since a couple of random numbers are used * in making the hash anyway. * * @param $hashName - The name of the hash as a form element. * * @param $configItem - The $configItem is used to look up the hash's * timeout. If the timeout is 0, or not set, we don't create a * hash and return null. */ protected static function createHash($hashName, $timeout) { $hash = null; if ($timeout > 0) { require_once 'Zend/Form/Element/Hash.php'; $hash = new Zend_Form_Element_Hash($hashName, array('decorators' => array('ViewHelper'), 'salt' => gettimeofday(), 'timeout' => $timeout)); } return $hash; }
function time_ms() { $tv = gettimeofday(); if ($tv) { $t = $tv['usec'] / 1000; $t += $tv['sec'] % 86400 * 1000; } return $t; }
function __construct($proxy) { function_exists('curl_init') || die('CURL Library Not Loaded'); //exit if don't install curl $this->m_proxies = split(",", file_get_contents($proxy)); $this->m_options = array('port' => 80, 'timeout' => 20, 'cookie' => false, 'ssl' => false, 'gzip' => true, 'proxy' => false); $t = gettimeofday(true); $this->m_headers = array("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0", 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Encoding: gzip, deflate', 'Accept-Language: en-US,en;q=0.5'); $this->m_multi = curl_multi_init(); }
function timer(&$stime) { if (isset($stime["sec"]) && isset($stime["usec"])) { $now = gettimeofday(); return $now["sec"] * 1000000 + $now["usec"] - ($stime["sec"] * 1000000 + $stime["usec"]); } else { $stime = gettimeofday(); return 0; } }
public function display() { //load calander $time = gettimeofday(); $time = getdate($time['sec']); $calender = new calender($time); $calender->build(); $this->smarty->assign('calender', $calender->getArray()); //$this->smarty->display('calender.tpl'); }
/** * Replace microtime() * * @category PHP * @package PHP_Compat * @license LGPL - http://www.gnu.org/licenses/lgpl.html * @copyright 2004-2007 Aidan Lister <*****@*****.**>, Arpad Ray <*****@*****.**> * @link http://php.net/function.microtime * @author Aidan Lister <*****@*****.**> * @author Arpad Ray <*****@*****.**> * @version $Revision: 1.3 $ * @since PHP 5.0.0 (Added optional get_as_float parameter) * @require PHP 4.0.0 (user_error) */ function php_compat_microtime($get_as_float = false) { if (!function_exists('gettimeofday')) { $time = time(); return $get_as_float ? $time * 1000000.0 : '0.00000000 ' . $time; } $gtod = gettimeofday(); $usec = $gtod['usec'] / 1000000.0; return $get_as_float ? (double) ($gtod['sec'] + $usec) : sprintf('%.8f ', $usec) . $gtod['sec']; }
function generate($serverID = '', $ip = '') { if (!$serverID) { $serverID = mt_rand(0, 0xffff); } if (!$ip) { $ip = mt_rand(0, 0xffffffff); } $t = gettimeofday(); return sprintf('%08x-%04x-%04x-%04x-%08x%04x', $t['sec'] & 0xffffffff, $t['usec'] & 0xffff, mt_rand(0, 0xffff), mt_rand(0, 0xffff), $ip, $serverID); }
public function dispatchLoopShutdown() { if (Globals::isDebug()) { $print = ""; self::$_time_end_render = gettimeofday(true); $print = $this->dumpPageRenderProfiler(self::$_time_start_render, self::$_time_end_render); $print .= $this->dumpCacheProfiler(); $print .= '<br><br>' . ProfilerLog::dumpLog(); $print .= $this->dumpDbProfiler(); $this->getResponse()->appendBody($print); } }
function dotest($args) { $n = 1; $doing = 'create'; $funcname = "test_" . $doing; $start = gettimeofday(); $this->{$funcname}($args); $end = gettimeofday(); $tm = timediff($start, $end); $speed = $n / $tm * 1000000; echo "use time: {$tm}, speed:{$speed}\n"; }
/** * @param int $length * @return string * @throws \Assert\AssertionFailedException */ public function genSecret($length = 24) { guard($length)->min(16, 'length must be at least 16 characters')->isModulus(8, 'length must be a multiple of 8'); while ($length--) { $c = @gettimeofday()['usec'] % 53; while ($c--) { mt_rand(); } @($secret .= static::$base32Map[mt_rand(0, 31)]); } return $secret; }
function check_uniqueness($table_name, $holder_id_column_name, $timestamp_column_name) { echo "Adding index to {$table_name}. This could take a while...\n"; $before = gettimeofday(); dpsql_query("\n ALTER TABLE {$table_name}\n ADD INDEX ({$holder_id_column_name},{$timestamp_column_name})\n "); $after = gettimeofday(); $diff = $after['sec'] - $before['sec'] + 1.0E-6 * ($after['usec'] - $before['usec']); echo "{$diff} seconds\n"; // 4.2 sec for user_teams_stats on .net // 414.0 sec for member_stats on .net echo "Looking for rows that violate uniqueness...\n"; $res = dpsql_query("\n SELECT {$holder_id_column_name}, {$timestamp_column_name}, COUNT(*) AS c\n FROM {$table_name}\n GROUP BY {$holder_id_column_name}, {$timestamp_column_name}\n HAVING c > 1\n ORDER BY {$timestamp_column_name}, {$holder_id_column_name}\n ") or die("Aborting"); if (mysql_num_rows($res) == 0) { $satisfies_uniqueness = TRUE; } else { echo "Some data in {$table_name} table does not satisfy uniqueness.\n"; echo "Probably they are just duplicate rows.\n"; echo "Attempting to clean them up...\n"; echo "\n"; $n_cleaned_cases = 0; $n_uncleanable_cases = 0; while (list($holder_id, $timestamp, $c) = mysql_fetch_row($res)) { echo "{$holder_id_column_name}={$holder_id} {$timestamp_column_name}={$timestamp} #rows={$c}: "; $res2 = dpsql_query("\n SELECT *\n FROM {$table_name}\n WHERE {$holder_id_column_name}={$holder_id} AND {$timestamp_column_name}={$timestamp}\n "); assert(mysql_num_rows($res2) == $c); if (all_rows_the_same($res2)) { echo "All rows the same. Deleting all but one.\n"; $all_but_one = $c - 1; $delete_query = "\n DELETE FROM {$table_name}\n WHERE {$holder_id_column_name}={$holder_id} AND {$timestamp_column_name}={$timestamp}\n LIMIT {$all_but_one}\n "; // echo "$delete_query\n"; dpsql_query($delete_query) or die("Aborting"); $n_cleaned_cases++; } else { echo "ROWS NOT ALL THE SAME!\n"; $n_uncleanable_cases++; } } echo "{$n_cleaned_cases} cases cleaned up\n"; echo "{$n_uncleanable_cases} cases could not be cleaned up\n"; $satisfies_uniqueness = $n_uncleanable_cases == 0; } echo "\n"; if ($satisfies_uniqueness) { echo "{$table_name} satisfies uniqueness constraint,\n"; echo "so should be okay to transfer to past_tallies.\n"; } else { echo "{$table_name} does not satisfy uniqueness constraint,\n"; echo "so pointless to try to transfer it to past_tallies.\n"; echo "You will have to fix it first.\n"; } return $satisfies_uniqueness; }
public function __construct() { $args_num = func_num_args(); $args = func_get_args(); switch ($args_num) { case 0: $time = getdate(); $timeofday = gettimeofday(); $this->hour = $time['hours']; $this->minute = $time['minutes']; $this->second = $time['seconds']; $this->microsecond = $timeofday['usec']; break; case 1: $time = false; if (is_int($args[0])) { $time = getdate($args[0]); } elseif (is_string($args[0])) { $time = getdate(strtotime($args[0])); } if (is_array($time)) { $this->hour = $time['hours']; $this->minute = $time['minutes']; $this->second = $time['seconds']; } elseif ($args[0] instanceof HproseTime) { $this->hour = $args[0]->hour; $this->minute = $args[0]->minute; $this->second = $args[0]->second; $this->microsecond = $args[0]->microsecond; } else { throw new Exception('Unexpected arguments'); } break; case 5: $this->utc = $args[4]; case 4: if ($args[3] < 0 || $args[3] > 999999) { throw new Exception('Unexpected arguments'); } $this->microsecond = $args[3]; case 3: if (!self::isValidTime($args[0], $args[1], $args[2])) { throw new Exception('Unexpected arguments'); } $this->hour = $args[0]; $this->minute = $args[1]; $this->second = $args[2]; break; default: throw new Exception('Unexpected arguments'); } }
private function genRequestId() { if (isset($_SERVER['HTTP_CLIENTAPPID'])) { return intval($_SERVER['HTTP_CLIENTAPPID']); } $reqip = App::getClientIp(); $time = gettimeofday(); $time = $time['sec'] * 100 + $time['usec']; $ip = ip2long($reqip); $id = ($time ^ $ip) & 0xffffffff; $id = Sign::sign64($id . '_' . rand(1, 800000000)); return $id; }
public static function genSecret($length = 24) { if ($length < 16 || $length % 8 != 0) { return ['err' => 'length must be a multiple of 8, and at least 16']; } while ($length--) { $c = @gettimeofday()['usec'] % 53; while ($c--) { mt_rand(); } @($secret .= self::$base32Map[mt_rand(0, 31)]); } return ['secret' => $secret]; }
function test_float() { //Get the value of pi $t = pi(); $timeStart = gettimeofday(); for ($i = 0; $i < 3000000; $i++) { //square root sqrt($t); } $timeEnd = gettimeofday(); $time = ($timeEnd["usec"] - $timeStart["usec"]) / 1000000 + $timeEnd["sec"] - $timeStart["sec"]; $time = round($time, 3) . "second"; return $time; }
private function test_io() { $fp = @fopen(PHPSELF, "r"); $timeStart = gettimeofday(); for ($i = 0; $i < 10000; $i++) { @fread($fp, 10240); @rewind($fp); } $timeEnd = gettimeofday(); @fclose($fp); $time = ($timeEnd["usec"] - $timeStart["usec"]) / 1000000 + $timeEnd["sec"] - $timeStart["sec"]; $time = round($time, 3) . "秒"; return $time; }