コード例 #1
0
ファイル: filesystem.php プロジェクト: noccy80/lepton-ng
 /**
  * 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'));
     }
 }
コード例 #2
0
ファイル: lunit.php プロジェクト: noccy80/lepton-ng
 function run()
 {
     $cases = Lunit::getCases();
     $casedata = array();
     // Enumerate the cases
     foreach ($cases as $case) {
         // Setup report structure
         $casereport = array();
         // Reflect the class to find methods and metadata
         $r = new ReflectionClass($case);
         $ml = $r->getMethods();
         $skip = false;
         $meta = LunitUtil::parseDoc($r->getDocComment());
         if (!isset($meta['description'])) {
             $meta['description'] = $case;
         }
         $meta['casename'] = $case;
         if (isset($meta['extensions'])) {
             $extn = explode(' ', $meta['extensions']);
             foreach ($extn as $ext) {
                 if (!extension_loaded($ext)) {
                     $skip = true;
                     $skipmsg = "Need extension: " . $ext;
                 }
             }
         }
         $casereport['meta'] = $meta;
         // Callback if set
         if ($this->statuscb) {
             $this->statuscb->onCaseBegin($case, $meta);
         }
         if ($this->dblog) {
             $this->dblog->onCaseBegin($case, $meta);
         }
         try {
             if (!$skip) {
                 $tc = new $case($this);
             }
             foreach ($ml as $method) {
                 $methodname = $method->getName();
                 if ($method->isPublic() && substr($methodname, 0, 1) != '_') {
                     $methodreport = array();
                     $tmeta = LunitUtil::parseDoc($method->getDocComment());
                     if (!isset($tmeta['description'])) {
                         $tmeta['description'] = $methodname;
                     }
                     if (!isset($tmeta['repeat'])) {
                         $tmeta['repeat'] = 1;
                     }
                     // Save meta to method report
                     $methodreport['meta'] = $tmeta;
                     // Times to repeat the test
                     $repeat = intval($tmeta['repeat']);
                     // Callback if set, then create timer
                     if ($this->statuscb) {
                         $this->statuscb->onTestBegin($methodname, $tmeta);
                     }
                     if ($this->dblog) {
                         $this->dblog->onTestBegin($methodname, $meta);
                     }
                     $methodreport['skipped'] = false;
                     $tavg = null;
                     $tmax = null;
                     $tmin = null;
                     if (!$skip) {
                         $tm = new Timer();
                         try {
                             $telapsed = array();
                             $ttotal = 0;
                             for ($n = 0; $n < $repeat; $n++) {
                                 $tm->start();
                                 $tc->{$methodname}();
                                 $tm->stop();
                                 $telapsed[] = $tm->getElapsed() * 1000;
                                 $ttotal += $tm->getElapsed() * 1000;
                             }
                             $ttot = math::sum($telapsed);
                             $tavg = math::average($telapsed);
                             $tmin = math::min($telapsed);
                             $tmax = math::max($telapsed);
                             $tdev = math::deviation($telapsed);
                             $methodreport['passed'] = true;
                             $methodreport['message'] = null;
                             if ($repeat > 1) {
                                 // console::write('%6.1fms <%6.1fms> %6.1fms ', $tmin, $tavg, $tmax);
                             } else {
                                 // console::write('%6.1fms ', $tmax);
                             }
                             if ($this->statuscb) {
                                 $this->statuscb->onTestEnd(true, null);
                             }
                             if ($this->dblog) {
                                 $this->dblog->onTestEnd(true, null);
                             }
                         } catch (LunitAssertionFailure $f) {
                             $tm->stop();
                             $methodreport['passed'] = false;
                             $methodreport['message'] = $f->getMessage();
                             if ($this->statuscb) {
                                 $this->statuscb->onTestEnd(false, $f->getMessage());
                             }
                             if ($this->dblog) {
                                 $this->dblog->onTestEnd(false, $f->getMessage());
                             }
                         } catch (LunitAssertionSkip $f) {
                             $tm->stop();
                             $methodreport['passed'] = false;
                             $methodreport['skipped'] = true;
                             $methodreport['message'] = 'Skipped';
                             if ($this->statuscb) {
                                 $this->statuscb->onTestEnd(null, $f->getMessage());
                             }
                             if ($this->dblog) {
                                 $this->dblog->onTestEnd(null, $f->getMessage());
                             }
                         } catch (Exception $e) {
                             $tm->stop();
                             $methodreport['passed'] = false;
                             $methodreport['message'] = $e->getMessage();
                             if ($this->statuscb) {
                                 $this->statuscb->onTestEnd(false, $e->getMessage());
                             }
                             if ($this->dblog) {
                                 $this->dblog->onTestEnd(false, $f->getMessage());
                             }
                         }
                     } else {
                         $methodreport['passed'] = false;
                         $methodreport['skipped'] = true;
                         $methodreport['message'] = $skipmsg;
                         $this->statuscb->onTestEnd(null, $skipmsg);
                         if ($this->dblog) {
                             $this->dblog->onTestEnd(null, $skipmsg);
                         }
                     }
                     $methodreport['elapsed'][] = $tm->getElapsed();
                     $methodreport['average'] = $tavg;
                     $methodreport['minmax'] = array($tmin, $tmax);
                     // Save report
                     $casereport['tests'][$methodname] = $methodreport;
                 }
             }
         } catch (Exception $e) {
             console::writeLn("Skipped due to exception: %s", $e->getMessage());
         }
         $casedata[$case] = $casereport;
         // Callback if set
         if ($this->statuscb) {
             $this->statuscb->onCaseEnd();
         }
         if ($this->dblog) {
             $this->dblog->onCaseEnd($casereport);
         }
     }
     $this->results = $casedata;
 }
コード例 #3
0
ファイル: base.php プロジェクト: noccy80/lepton-ng
 /**
  *
  */
 static function run($class)
 {
     static $ic = 0;
     $args = func_get_args();
     $args = array_slice($args, 1);
     Console::debugEx(LOG_EXTENDED, __CLASS__, "Inspecting environment module state:\n%s", ModuleManager::debug());
     $ic++;
     if (class_exists($class)) {
         $rv = 0;
         $apptimer = new Timer();
         try {
             $instance = new $class();
             if (!$instance instanceof IApplication) {
                 console::warn("FATAL: Application is not instance of IApplication");
                 return RETURN_ERROR;
             }
             Console::debugEx(LOG_BASIC, __CLASS__, "Invoking application instance from %s.", $class);
             $apptimer->start();
             if (is_callable(array($instance, 'run'))) {
                 $rv = call_user_func_array(array($instance, 'run'), $args);
             } else {
                 console::writeLn("Requested application class %s is not runnable.", $class);
             }
             $apptimer->stop();
             unset($instance);
             Console::debugEx(LOG_BASIC, __CLASS__, "Main method exited with code %d after %.2f seconds.", $rv, $apptimer->getElapsed());
         } catch (Exception $e) {
             throw $e;
         }
         $ic--;
         if ($ic == 0) {
             return $rv;
         }
     } else {
         $ic--;
         if ($ic == 0) {
             Console::warn('FATAL: Application class %s not found!', $class);
             exit(RETURN_ERROR);
         } else {
             Console::warn('Application class %s not found!', $class);
         }
     }
 }
コード例 #4
0
ファイル: tick.php プロジェクト: scipper/applicationserver
<?php

include "Timer.php";
/*declare(ticks = 1);

function tickFunction() {

}

register_tick_function("tickFunction");
*/
$running = true;
$iter = 0;
$timer = new Timer();
while ($running) {
    $iter++;
    $timer->update();
    if ($iter >= 10000000) {
        $running = false;
    }
}
echo $timer->getElapsed() . PHP_EOL;
コード例 #5
0
ファイル: geonames.php プロジェクト: noccy80/lepton-ng
 function download()
 {
     $this->createTables();
     console::writeLn("Downloading updated sets...");
     $e = str_repeat("", 70);
     $ef = str_repeat("", 70) . str_repeat(" ", 70) . str_repeat("", 70);
     $tot = count($this->data['update']);
     $c = 0;
     foreach ($this->data['update'] as $fn => $void) {
         $this->total = array('max' => $tot, 'current' => $c++, 'percent' => 100 / $tot * $c);
         $this->activity = "Downloading";
         $this->activityobject = $fn;
         $t = new Timer(true);
         $dl = new HttpDownload($this->baseurl . $fn, base::appPath() . '/geocache/' . $fn, array('onprogress' => new Callback($this, 'onprogress')));
         $td = $t->getElapsed();
         $this->clearTask();
         $flen = filesize(base::appPath() . '/geocache/' . $fn);
         console::writeLn("%s downloaded (%d bytes in %.1f seconds, %.1f KB/s)", $fn, $flen, $td, $flen / 1024 / $td);
     }
 }