本文整理汇总了PHP中Timer::start方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::start方法的具体用法?PHP Timer::start怎么用?PHP Timer::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initResource
public static function initResource($inifile)
{
//Timer::start("a");
$arr = parse_ini_file($inifile);
/*
Timer::stop("a");
Timer::start("b");
$p = new Properties();
$fp = fopen($inifile.'2','r');
$p->load($fp);
//print_r($p->propertyNames());
Timer::stop("b");
Timer::printTime(10);
die();
*/
if (!is_array($arr) || !count($arr) > 0) {
die("core/ResourcePool : inifile " . $inifile . " not found\n");
}
Timer::start('ResourcePool::init::' . $class);
$class = new ReflectionClass($arr['className']);
$resourceInstance = $class->newInstance($arr);
$resourceInstance->init();
self::$resources = $resourceInstance;
Timer::stop('ResourcePool::init::' . $class);
//$resourceInstance
//$resourceInstance->setStatus($status);
}
示例2: testDuration
/**
* Tests duration measuring.
*/
public function testDuration()
{
$mt = microtime(true);
$name = Timer::start();
$delta = Timer::stop($name);
$outerDelta = microtime(true) - $mt;
// Measured time is greater than 0
$this->assertGreaterThan(0, $delta);
// Measured time is less than the time between the two function calls
$this->assertLessThan($outerDelta, $delta);
// Non-existent timer
$this->assertSame(0, Timer::stop('foo'));
// Start 4 timers
$names = array('foo', 'bar', 'tmp', 'ohai');
$times = array_fill_keys($names, 0);
foreach ($names as $name) {
Timer::start($name);
}
// End them in reverse order
foreach (array_reverse($names) as $name) {
$times[$name] = Timer::stop($name);
}
// The measured time is supposed to be in descending order
foreach ($names as $i => $name) {
$this->assertGreaterThan(0, $times[$name]);
if ($i > 0) {
$this->assertLessThan($times[$names[$i - 1]], $times[$name]);
}
}
}
示例3: __new_feed
/**
* Provided a URL, will return an array representing the feed item for that
* URL. A feed item contains the content, url, simplepie object, and failure
* status for the URL passed. Handles caching of content requests.
*
* @return array
* @author Jared Lang
**/
protected static function __new_feed($url)
{
$timer = Timer::start();
require_once THEME_DIR . '/third-party/simplepie.php';
$simplepie = null;
$failed = False;
$cache_key = 'feedmanager-' . md5($url);
$content = get_site_transient($cache_key);
if ($content === False) {
$content = @file_get_contents($url);
if ($content === False) {
$failed = True;
$content = null;
error_log('FeedManager failed to fetch data using url of ' . $url);
} else {
set_site_transient($cache_key, $content, self::$cache_length);
}
}
if ($content) {
$simplepie = new SimplePie();
$simplepie->set_raw_data($content);
$simplepie->init();
$simplepie->handle_content_type();
if ($simplepie->error) {
error_log($simplepie->error);
$simplepie = null;
$failed = True;
}
} else {
$failed = True;
}
$elapsed = round($timer->elapsed() * 1000);
debug("__new_feed: {$elapsed} milliseconds");
return array('content' => $content, 'url' => $url, 'simplepie' => $simplepie, 'failed' => $failed);
}
示例4: extractPage
public function extractPage($pageID, $pageTitle, $pageSource)
{
$this->extractor->setPageURI($pageID);
if (!$this->extractor->isActive()) {
return $result = new ExtractionResult($pageID, $this->extractor->getLanguage(), $this->getExtractorID());
}
Timer::start($this->extractor->getExtractorID());
$result = $this->extractor->extractPage($pageID, $pageTitle, $pageSource);
Timer::stop($this->extractor->getExtractorID());
Timer::start('validation');
//$this->extractor->check();
if (Options::getOption('validateExtractors')) {
ValidateExtractionResult::validate($result, $this->extractor);
}
Timer::stop('validation');
Statistics::increaseCount($this->extractor->getExtractorID(), 'created_Triples', count($result->getTriples()));
Statistics::increaseCount('Total', 'created_Triples', count($result->getTriples()));
if ($this->extractor->isGenerateOWLAxiomAnnotations()) {
$triples = $result->getTriples();
if (count($triples) > 0) {
foreach ($triples as $triple) {
$triple->addDCModifiedAnnotation();
$triple->addExtractedByAnnotation($this->extractor->getExtractorID());
}
}
}
return $result;
}
示例5: getSource
public function getSource($pageID)
{
Timer::start('LiveFromFileCollection');
$content = file_get_contents($this->currentArticleFile);
Timer::stop('LiveFromFileCollection');
return $content;
}
示例6: boot
function boot()
{
if (!defined('APP_ROOT')) {
define('APP_ROOT', dirname(dirname(__FILE__)));
}
Timer::start();
}
示例7: 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";
}
}
示例8: start
/**
* Start
* @param digits number of decimals to calculate
* @return nothing
*/
function start($digits = null)
{
if (!empty($digits)) {
self::$digits = $digits;
}
self::$start = microtime(true);
self::$started = true;
}
示例9: elapsedTimeGreaterThanZeroUsingStartAndStop
public function elapsedTimeGreaterThanZeroUsingStartAndStop()
{
$fixture = new Timer();
$fixture->start();
usleep(100 * 1000);
$fixture->stop();
$elapsed = $fixture->elapsedTime();
$this->assertTrue($elapsed > 0.0, 'Elapsed time should be greater than zero');
}
示例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;
}
示例11: execute
/**
* Triggers the ExtractionJob
* @param $job: An ExtractionJob
*/
public function execute($job)
{
$language = $job->getPageCollection()->getLanguage();
// Initialize Extractors and Destination
foreach (new ArrayObject($job->getExtractionGroups()) as $group) {
$group->getDestination()->start();
foreach (new ArrayObject($group->getExtractors()) as $extractor) {
$extractor->start($language);
}
}
$this->log(DEBUG, "extractors started");
// Extract content from WikiPedia Pages
// The PageTitleIterator loops over all pages from a PageCollection
foreach ($job->getPageTitleIterator() as $pageTitle) {
Timer::start(get_class($job->getPageCollection()) . '::getSource');
$pageSource = $job->getPageCollection()->getSource($pageTitle);
Timer::stop(get_class($job->getPageCollection()) . '::getSource');
$pageID = $this->getPageID($pageTitle, $pageSource, $language);
if ($pageID === false || $pageID == NULL) {
continue;
}
$this->log(DEBUG, "begin page extraction");
// Extract the content and pass it to the Destination
foreach (new ArrayObject($job->getExtractionGroups()) as $group) {
$destination = $group->getDestination();
foreach (new ArrayObject($group->getExtractors()) as $extractor) {
$this->log(DEBUG, "extractPage: " . $extractor->getExtractorID());
$result = $extractor->extractPage($pageID, $pageTitle, $pageSource);
Timer::start('destination:accept');
$destination->accept($result);
Timer::stop('destination:accept');
}
//end foreach
}
//end outer foreach
}
// Close Destinations and Extractors
foreach (new ArrayObject($job->getExtractionGroups()) as $group) {
Timer::start('destination:finish');
$group->getDestination()->finish();
Timer::stop('destination:finish');
// Optional MetaInformation is stored in MetaDestination
// Currently only used for InfoboxExtraction for predicates
$metaDestination = $group->getMetaDestination();
if ($metaDestination != null) {
$metaDestination->start();
foreach (new ArrayObject($group->getExtractors()) as $extractor) {
$result = $extractor->finish();
if ($result != null) {
$metaDestination->accept($result);
}
}
$metaDestination->finish();
}
}
}
示例12: 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);
}
示例13: run
/**
* Run benchmark.
*
* @throws BenchEx
*
* @return Bench
*/
public function run()
{
foreach ($this->benchmarks as $name => $benchmark) {
$this->timer->start($name);
$benchmark($this->iterations);
$this->timer->stop($name);
}
$this->createSummary();
return $this;
}
示例14: testElapsedTimeGivesSameResultAsTimersArray
public function testElapsedTimeGivesSameResultAsTimersArray()
{
$timer = new Timer();
$timer->start('test1');
sleep(1);
$timer->stop('test1');
$timers = $timer->getTimers();
$expected = $timers['test1']['duration'];
$this->assertEquals($expected, $timer->getElapsedTime('test1'));
}
示例15: 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";
}
}
}