本文整理汇总了PHP中Timer类的典型用法代码示例。如果您正苦于以下问题:PHP Timer类的具体用法?PHP Timer怎么用?PHP Timer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Timer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
# Only run once.
if ($this->result !== null) {
return $this;
}
# It's nice to have this as an implicit condition.
if ($this->should_except) {
$this->conditions[] = new Condition(function ($result) {
return $result->exception() !== null;
}, 'should throw exception');
} else {
$this->conditions[] = new Condition(function ($result) {
return $result->exception() === null;
}, 'should not throw exception');
}
ob_start();
$value = null;
$exception = null;
$timer = new Timer();
try {
$value = call_user_func($this->closure, $this);
} catch (\Exception $e) {
$exception = $e;
}
$output = ob_get_clean();
$this->result = new Result($value, $output, $timer->stop(), $exception);
return $this;
}
开发者ID:maxvu,项目名称:sliver,代码行数:29,代码来源:Test.php
示例2: parse
function parse()
{
if ($this->doParseRSS) {
require_once "include/domit_rss/timer.php";
$timer = new Timer();
$success = false;
$timer->start();
if (!defined('DOMIT_RSS_INCLUDE_PATH')) {
define('DOMIT_RSS_INCLUDE_PATH', dirname(__FILE__) . "/");
}
switch ($this->rssparser) {
case "domit_rss_lite":
require_once DOMIT_RSS_INCLUDE_PATH . 'xml_domit_rss_lite.php';
$this->rssdoc = new xml_domit_rss_document_lite($this->rssurl);
break;
case "domit_rss":
require_once DOMIT_RSS_INCLUDE_PATH . 'xml_domit_rss.php';
$this->rssdoc = new xml_domit_rss_document($this->rssurl);
break;
}
// switch
$timer->stop();
$this->displayNew();
echo "<br /><br />Time elapsed: " . $timer->getTime() . "seconds<br /><br />\n";
}
}
开发者ID:klr2003,项目名称:sourceread,代码行数:26,代码来源:testing_domitrss.php
示例3: myquery
function myquery($query)
{
global $time_mysql_query;
global $numsql;
global $debuginfo;
$backtrace = debug_backtrace();
$back1 = $backtrace;
$backtrace = " in : " . $backtrace[0]["file"] . ", on line: " . $backtrace[0]["line"] . "";
if (debug_run == 1) {
$MyTimerSQL = new Timer();
$MyTimerSQL->Init();
//$result = mysql_query($query) or trigger_error(mysql_errno() . ": <b>" . mysql_error() . $backtrace . format_query($query) , E_USER_ERROR);
$result = mysql_query($query) or send_error(mysql_errno() . ": <b>" . mysql_error() . $backtrace . "<br /><br /><p>Query: " . $query . "</p>", $backtrace);
$exec_time_mysql = $MyTimerSQL->GetTime(5);
$GLOBALS['numsql']++;
$time_mysql_query += $exec_time_mysql;
$GLOBALS['debuginfo'] .= '<tr><td>' . $query . '</td><td><span style="color:#C0FFFF">' . $exec_time_mysql . '</span></td><td><span style="color:lightgrey">' . $backtrace . '</span></tr>';
if (isset($GLOBALS['debug'][$back1[0]['file']])) {
$GLOBALS['debug'][$back1[0]['file']]['time_sql'] += $exec_time_mysql;
$GLOBALS['debug'][$back1[0]['file']]['count_sql'] += 1;
}
} else {
$result = mysql_query($query);
}
/*
if (strpos($query,"EXP")!==FALSE AND strpos($query,"game_users")!==FALSE AND strpos($query,"UPDATE")!==FALSE)
{
mysql_query("INSERT INTO query_log (query,timestamp,filename) VALUES ('$query',".time().",'$backtrace')");
}
*/
return $result;
}
开发者ID:themiddleearth,项目名称:RPG.SU,代码行数:32,代码来源:config.inc.php
示例4: populateCharacters
private static function populateCharacters($db)
{
global $baseDir;
$timer = new Timer();
$maxTime = 65 * 1000;
// Reset 222's that are over a week old
$db->execute("update zz_api set errorCode = 0 where errorCode = 222 and lastValidation <= date_sub(now(), interval 7 day)");
$apiCount = $db->queryField("select count(*) count from zz_api where errorCode not in (203, 220, 222) and lastValidation <= date_add(now(), interval 1 minute)", "count", array(), 0);
if ($apiCount == 0) {
return;
}
$fetchesPerSecond = 25;
$iterationCount = 0;
while ($timer->stop() < $maxTime) {
$keyIDs = $db->query("select distinct keyID from zz_api where errorCode not in (203, 220, 222) and lastValidation < date_sub(now(), interval 2 hour)\r\n\t\t\t\t\torder by lastValidation, dateAdded desc limit 100", array(), 0);
foreach ($keyIDs as $row) {
if (Util::isMaintenanceMode()) {
return;
}
$keyID = $row["keyID"];
$m = $iterationCount % $fetchesPerSecond;
$db->execute("update zz_api set lastValidation = date_add(lastValidation, interval 5 minute) where keyID = :keyID", array(":keyID" => $keyID));
$command = "flock -w 60 {$baseDir}/cache/locks/populate.{$m} php5 {$baseDir}/cli.php apiFetchCharacters " . escapeshellarg($keyID);
//Log::log("$command");
exec("{$command} >/dev/null 2>/dev/null &");
$iterationCount++;
if ($iterationCount % $fetchesPerSecond == 0) {
sleep(1);
}
}
sleep(1);
}
}
开发者ID:Covert-Inferno,项目名称:zKillboard,代码行数:33,代码来源:cli_populateCharacters.php
示例5: dispatchLoopShutdown
public function dispatchLoopShutdown()
{
//
// Force output to be sent - we need the client to have the page before
// we start flushing progress bar updates
//
$app = AppController::getInstance();
$req = $app->getRequest();
$resp = $app->getResponse();
$resp->sendResponse();
$resp->clearContent();
//
// Do reindexing
//
if ($req->isLoggedIn() && $req->user->canDoAction('can_do_search_reindex')) {
set_time_limit(3600 * 8);
$o_db = new Db();
$t_timer = new Timer();
$o_dm = Datamodel::load();
$va_table_names = $o_dm->getTableNames();
$vn_tc = 0;
foreach ($va_table_names as $vs_table) {
if ($o_instance = $o_dm->getInstanceByTableName($vs_table)) {
if ($o_instance->isHierarchical()) {
if (!$o_instance->rebuildAllHierarchicalIndexes()) {
$o_instance->rebuildHierarchicalIndex();
}
}
caIncrementHierachicalReindexProgress(_t('Rebuilding hierarchical index for %1', $o_instance->getProperty('NAME_PLURAL')), $t_timer->getTime(2), memory_get_usage(true), $va_table_names, $o_instance->tableNum(), $o_instance->getProperty('NAME_PLURAL'), $vn_tc + 1);
}
$vn_tc++;
}
caIncrementHierachicalReindexProgress(_t('Index rebuild complete!'), $t_timer->getTime(2), memory_get_usage(true), $va_table_names, null, null, sizeof($va_table_names));
}
}
开发者ID:idiscussforum,项目名称:providence,代码行数:35,代码来源:HierarchicalReindexingProgress.php
示例6: getSingleBenchmarkTimeSecs
/**
* Returns single benchmark time in seconds
*
* @param string $benchmarkLambdaFunction Benchmark lambda function
* @param array $benchmarkFunctionArgumentsArray Benchmark arguments array
*
* @return float
*/
function getSingleBenchmarkTimeSecs($benchmarkLambdaFunction, array $benchmarkFunctionArgumentsArray)
{
$autoStartTimer = 1;
$timer = new Timer($autoStartTimer);
call_user_func_array($benchmarkLambdaFunction, $benchmarkFunctionArgumentsArray);
return $timer->get();
}
开发者ID:OlOst,项目名称:magecert_ce,代码行数:15,代码来源:benchmark_cat_save.php
示例7: open
/**
* Open a message store.
*
* @param string $identity The identity to open as an URI
*/
function open($identity)
{
$file = parse_url($identity, PHP_URL_HOST);
// Set up the paths and objects we need
$this->mbpath = config::get(FilesystemMailStorage::KEY_STORAGE_PATH, BASE_PATH . 'cache') . '/' . $file . '.xml';
$this->lockpath = config::get(FilesystemMailStorage::KEY_STORAGE_PATH, BASE_PATH . 'cache') . '/' . $file . '.lock';
$this->mbox = new DOMDocument('1.0');
// Primitive locking for the win :) This should be more than enough
// for whoever decides to use this. Will probably not be too good to
// the disk under heavy load.
$t = new Timer(true);
$to = config::get(FilesystemMailStorage::KEY_LOCK_TIMEOUT, FilesystemMailStorage::DEF_LOCK_TIMEOUT);
console::debugEx(LOG_DEBUG, __CLASS__, "Acquiring lock...");
while (file_exists($this->lockpath)) {
usleep(100000);
if ($t->getElapsed() > $to) {
throw new MailException("Timed out waiting for lock.");
}
}
unset($t);
$this->lock = fopen($this->lockpath, 'w');
// Check if the mailbox exists
if (file_exists($this->mbpath)) {
$this->mbox->load($this->mbpath);
console::debugEx(LOG_DEBUG, __CLASS__, "Loaded mailbox %s", $this->mbpath);
} else {
console::debugEx(LOG_DEBUG, __CLASS__, "Created new mailbox %s", $this->mbpath);
$this->mbox->appendChild($this->mbox->createElement('mailbox'));
}
}
开发者ID:noccy80,项目名称:lepton-ng,代码行数:35,代码来源:filesystem.php
示例8: start
/**
* {@inheritdoc}
*/
public function start(Timer $timer)
{
if (!isset($this->timers[$timer])) {
$interval = $timer->getInterval();
$event = $this->loop->timer($interval, $timer->isPeriodic() ? $interval : 0, $this->callback, $timer);
$this->timers[$timer] = $event;
}
}
开发者ID:valentinkh1,项目名称:icicle,代码行数:11,代码来源:EvTimerManager.php
示例9: serializeLowMemory
/**
* Try to emulate SAX type serialization, because otherwise it goes out of memory
* @param $data
* @param $output Sets the output to this variable
* @param $clear_data If set, $data is cleared once serialization is done
* @return unknown_type
*/
function serializeLowMemory(&$data, &$output, $clear_data = false, $batch_size = 1000)
{
if ($this->serializer == false) {
$serializer_options = array('addDecl' => FALSE, 'encoding' => 'ISO-8859-1', 'indent' => ' ', 'rootName' => 'item', 'defaultTagName' => 'item');
$this->serializer = new XML_Serializer($serializer_options);
}
list($temp_file_name, $http) = Util::getTemporaryFile('xml-serialize', 'xml');
$this->logger->debug("Using temporary file for XML Serialization: {$temp_file_name}");
$fh = fopen($temp_file_name, 'w');
fwrite($fh, "<?xml version='1.0' encoding='ISO-8859-1'?>\n<root>\n");
if (Util::is_assoc($data)) {
foreach ($data as $top_level_tag_key => &$data_value) {
$first = true;
fwrite($fh, "<{$top_level_tag_key}>\n");
if (is_array($data_value)) {
$count = 0;
$string = "";
$timer = new Timer('SerializationTimer');
$timer->start();
foreach ($data_value as $second_level_key => &$second_level_value) {
$string .= $this->serializeXml($second_level_value) . "\n";
$count++;
if ($count % $batch_size == 0) {
$timer->stop();
fwrite($fh, $string);
$string = "";
$this->logger->debug("{$top_level_tag_key} > Serialized upto row - " . $count++ . ". Time Taken : " . $timer->getLastLapTime() . "s. Current Memory usage: " . memory_get_usage() / 1000000 . "MB");
$timer->start();
}
if ($first) {
$this->logger->debug("{$top_level_tag_key} > XML Serialization Sample Data : Key is {$second_level_key}\nValue is " . print_r($second_level_value, true));
$first = false;
}
//if clear data is set, clear the second level value
if ($clear_data) {
$second_level_value = false;
}
//fflush($fh);
}
//the last batch might not be complete
if ($string != "") {
$timer->stop();
fwrite($fh, $string);
$string = "";
}
}
fwrite($fh, "</{$top_level_tag_key}>\n");
if ($clear_data) {
$data_value = false;
}
}
}
fwrite($fh, "\n</root>");
fclose($fh);
$output = file_get_contents($temp_file_name);
}
开发者ID:rajnishp,项目名称:bjs,代码行数:63,代码来源:Xml.php
示例10: runPlugin
public function runPlugin($input = array())
{
$badContent = 1;
$goodContent = 1;
if (!isset($input['tracerouteFailDomain'])) {
$input['tracerouteFailDomain'] = '';
}
if (!isset($input['followRedirects'])) {
$input['followRedirects'] = 1;
}
$input['followRedirects'] = (bool) $input['followRedirects'];
for ($i = $input['attempts']; $i <= $input['attempts']; $i++) {
$output = Plugin::$output;
///set defaults for all output
$t = new Timer();
$t->start();
$output['returnContent'] = HttpContentPlugin::doHTTPGet($input['url'], $input['maxConnectTimeoutSeconds'], $input['maxRequestTimeoutSeconds'], $input['followRedirects']);
// echo $output['returnContent'];
$output['responseTimeMs'] = (int) $t->stop();
$output['measuredValue'] = $output['returnContent'];
if (trim($input['goodContent']) != '') {
$goodContent = strpos($output['returnContent'], $input['goodContent']) === false ? 0 : 1;
}
if (trim($input['badContent']) != '') {
$badContent = strpos($output['returnContent'], $input['badContent']) === false ? 1 : 0;
}
//default to down
$output['currentStatus'] = 0;
//if its already bad, then its bad.
if ($goodContent + $badContent == 2) {
$output['currentStatus'] = 1;
}
if ($output['currentStatus'] == 1) {
//we've got what we wanted
break;
} else {
//else keep going till we do or hit max attempts
if (isset($input['attemptWait']) && $input['attemptWait'] !== 0) {
usleep($input['attemptWait'] * 1000);
}
}
}
//html email
$output['htmlEmail'] = 1;
if ($output['currentStatus'] == 0 && $input['tracerouteFailDomain'] != '') {
$tmpfname = tempnam("/tmp", "phpMonitorHTTPContent");
// do here something
$cmd = '/usr/sbin/mtr --report --report-cycles 5 ' . $input['tracerouteFailDomain'] . ' > ' . $tmpfname . ' 2>&1';
exec($cmd);
$return = file_get_contents($tmpfname);
unlink($tmpfname);
// echo $cmd;
$output['returnContent'] = $output['returnContent'] . "\n\n<pre>{$return}</pre>";
}
return $output;
}
开发者ID:laiello,项目名称:phpmonitoring,代码行数:56,代码来源:HttpContent.plugin.php
示例11: start
/**
* {@inheritdoc}
*/
public function start(Timer $timer)
{
$flags = Event::TIMEOUT;
if ($timer->isPeriodic()) {
$flags |= Event::PERSIST;
}
$event = new Event($this->base, -1, $flags, $this->callback, $timer);
$this->timers[$timer] = $event;
$event->add($timer->getInterval());
}
开发者ID:valentinkh1,项目名称:icicle,代码行数:13,代码来源:EventTimerManager.php
示例12: Start
/**
*
*
*
*
* @return Timer
*/
public static function Start()
{
static $instance;
if (!isset($instance)) {
$instance = new Timer();
}
$time = $instance->GetMicrotime();
array_push($instance->startTimes, $time);
return $instance;
}
开发者ID:ssgonchar,项目名称:FastModel,代码行数:17,代码来源:Timer.php
示例13: start
/**
* {@inheritdoc}
*/
public function start(Timer $timer)
{
if (!isset($this->timers[$timer])) {
$handle = \uv_timer_init($this->loopHandle);
$interval = $timer->getInterval() * self::MILLISEC_PER_SEC;
\uv_timer_start($handle, $interval, $timer->isPeriodic() ? $interval : 0, $this->callback);
$this->timers[$timer] = $handle;
$this->handles[(int) $handle] = $timer;
}
}
开发者ID:valentinkh1,项目名称:icicle,代码行数:13,代码来源:UvTimerManager.php
示例14: parse
function parse()
{
if ($this->xmlaction != null) {
require_once "timer.php";
$timer = new Timer();
$success = false;
$this->saxparser == "saxy" ? $parseSAXY = true : ($parseSAXY = false);
$timer->start();
switch ($this->domparser) {
case "domit":
//change this to the domit path
require_once 'xml_domit_parser.php';
$this->xmldoc =& new DOMIT_Document();
$this->xmldoc->expandEmptyElementTags(true);
$this->xmldoc->setNamespaceAwareness(true);
break;
case "domitlite":
//change this to the domit lite path
require_once 'xml_domit_lite_parser.php';
$this->xmldoc =& new DOMIT_Lite_Document();
break;
}
// switch
switch ($this->xmlaction) {
case "parsefile":
$success = $this->xmldoc->loadXML($this->xmlfile, $parseSAXY);
break;
case "parseurl":
$success = $this->xmldoc->loadXML("http://" . $this->xmlurl, $parseSAXY);
break;
case "parsetext":
$success = $this->xmldoc->parseXML($this->xmltext, $parseSAXY);
break;
}
$timer->stop();
if ($success) {
echo "<br /><br />Time elapsed: " . $timer->getTime() . "seconds<br /><br />\n";
if ($this->xmloutput == "tostring") {
echo $this->xmldoc->toString(true);
} else {
if ($this->xmloutput == "tonormalizedstring") {
echo $this->xmldoc->toNormalizedString(true);
} else {
if ($this->xmloutput == "toarray") {
echo "<pre>\n";
print_r($this->xmldoc->toArray());
echo "</pre>\n";
}
}
}
} else {
echo "<br /><br />Parsing error: xml document may be invalid or malformed.\n";
}
}
}
开发者ID:BackupTheBerlios,项目名称:openology-svn,代码行数:55,代码来源:testing_domit.php
示例15: buildTree
/**
* Return a tree of time periods from a Timer
*
* @param Timer $timer Timer object
* @return array
*/
public function buildTree(Timer $timer)
{
$times = $timer->getTimes();
if (!isset($times[':end'])) {
$times[':end'] = microtime();
}
$begin = $this->findBeginTime($times);
$end = $this->findEndTime($times);
$this->total = $this->diffMicrotime($begin, $end);
return $this->analyzePeriod('', $times);
}
开发者ID:elgg,项目名称:elgg,代码行数:17,代码来源:Profiler.php
示例16: testSaveSimple
public function testSaveSimple()
{
//Logger::getInstance()->on();
YuppLoader::load('core.support', 'Timer');
$timer = new Timer();
$timer->start();
$bot = new Botella(array("material" => "vidrio", "capacidad" => 1.5, "tapaRosca" => true));
$this->assert($bot->save(), 'Test guardar 1 ' . print_r($bot->getErrors(), true));
$timer->stop();
echo 'Time: ' . $timer->getElapsedTime() . '<br/>';
//Logger::getInstance()->off();
}
开发者ID:fkali,项目名称:yupp,代码行数:12,代码来源:apps.tests.tests.TestCase001.class.php
示例17: run
public final function run(SystemUnderTest $systemUnderTest, $times)
{
$systemUnderTest->warmUp();
$this->warmUp($systemUnderTest);
$timer = new Timer($this->getName());
$systemUnderTest->start();
for ($i = 0; $i < $times; $i++) {
$this->performTest($systemUnderTest, $i);
}
$systemUnderTest->end();
return $timer->getElapsedTime() * 1000;
}
开发者ID:pkdevbox,项目名称:orm-benchmarking-suite,代码行数:12,代码来源:PerformanceTest.php
示例18: testStopChildren
public function testStopChildren()
{
// Init
$timer = new Timer();
// Process
$timer->start('mysql.sql.query.response.parsing', true);
usleep(50000);
$timer->stop('mysql.sql');
usleep(50000);
$value = $timer('mysql.sql.query.response.parsing');
// Assert
$this->assertEquals(true, $value > 0.045 && $value < 0.55);
}
开发者ID:ershov-ilya,项目名称:timer.class.php,代码行数:13,代码来源:TimerTest.php
示例19: instance
/**
* Lazy loading of Timer class instance.
*
* @return Timer
*/
public static function instance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
开发者ID:ndobromirov,项目名称:php_course_2012,代码行数:12,代码来源:Timer.php
示例20: boot
function boot()
{
if (!defined('APP_ROOT')) {
define('APP_ROOT', dirname(dirname(__FILE__)));
}
Timer::start();
}
开发者ID:sxtxixtxcxh,项目名称:Cheezy,代码行数:7,代码来源:framework.php
注:本文中的Timer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论