コード例 #1
0
 /**
  * Decorate a final underlying connection with ability to track
  * statistical information.
  *
  * @param HttpConnection $connection underlying connection to wrap
  * @returns HttpConnection decorated connection
  */
 public function hookFinalConnection(HttpConnection $connection)
 {
     if ($this->finalConnection !== null) {
         throw new IllegalStateException('Final connection already set');
     }
     $finalConnection = new StatsConnection($connection, new SystemTimer());
     $this->finalStats = $finalConnection->getStats();
     return $finalConnection;
 }
コード例 #2
0
 public function testStatistics()
 {
     $mockConnection = $this->newConnection();
     $mockTimer = $this->getMock('fajr\\libfajr\\base\\MutableTimer', array('reset', 'getElapsedTime'));
     $statsConnection = new StatsConnection($mockConnection, $mockTimer);
     $mockTimer->expects($this->any())->method('getElapsedTime')->will($this->returnValue(0.1));
     $response0 = "1234";
     $response1 = "123456789";
     $response2 = "1";
     $response4 = "12345";
     $mockConnection->expects($this->at(0))->method('get')->will($this->returnValue($response0));
     $mockConnection->expects($this->at(1))->method('post')->will($this->returnValue($response1));
     $mockConnection->expects($this->at(2))->method('get')->will($this->returnValue($response2));
     $mockConnection->expects($this->at(3))->method('post')->will($this->throwException(new Exception()));
     $mockConnection->expects($this->at(4))->method('get')->will($this->returnValue($response4));
     $statsConnection->get(new NullTrace(), 'url');
     $statsConnection->post(new NullTrace(), 'url', array());
     $statsConnection->get(new NullTrace(), 'url');
     try {
         $statsConnection->post(new NullTrace(), 'url', array());
     } catch (Exception $e) {
     }
     $statsConnection->get(new NullTrace(), 'url');
     $stats = $statsConnection->getStats();
     $this->assertEquals(1, $stats->getErrorCount());
     $this->assertEquals(5, $stats->getRequestCount());
     $this->assertEquals(19, $stats->getDownloadedBytes());
     $this->assertEquals(0.5, $stats->getTotalTime(), '', 0.01);
 }
コード例 #3
0
ファイル: fajr.php プロジェクト: BGCX067/fajr-svn-to-git
 public function run()
 {
     $timer = new SystemTimer();
     $connection = null;
     $statsConnection = null;
     $rawStatsConnection = null;
     $trace = new NullTrace();
     if (FajrConfig::get('Debug.Trace') === true) {
         $trace = new HtmlTrace($timer, "--Trace--");
     }
     try {
         Input::prepare();
         $login = Input::get('login');
         Input::set('login', null);
         $krbpwd = Input::get('krbpwd');
         Input::set('krbpwd', null);
         $cosignCookie = Input::get('cosignCookie');
         Input::set('cosignCookie', null);
         // FIXME this should be refactored
         if ($login !== null && $krbpwd !== null || $cosignCookie !== null) {
             // we are going to log in, so we get a clean session
             // this needs to be done before a connection
             // is created, because we pass cookie file name
             // that contains session_id into AIS2CurlConnection
             // If we regenerated the session id afterwards,
             // we could not find the cookie file after a redirect
             FajrUtils::dropSession();
         }
         $connection = new connection\CurlConnection(FajrUtils::getCookieFile());
         $rawStatsConnection = new connection\StatsConnection($connection, new SystemTimer());
         $connection = $rawStatsConnection;
         $connection = new connection\GzipDecompressingConnection($connection, FajrConfig::getDirectory('Path.Temporary'));
         $connection = new connection\AIS2ErrorCheckingConnection($connection);
         $statsConnection = new connection\StatsConnection($connection, new SystemTimer());
         $connection = $statsConnection;
         $simpleConnection = new connection\HttpToSimpleConnectionAdapter($connection);
         AIS2Utils::connection($simpleConnection);
         // toto tu je docasne
         if (Input::get('logout') !== null) {
             FajrUtils::logout($connection);
             FajrUtils::redirect();
         }
         if ($login !== null && $krbpwd !== null) {
             $loggedIn = FajrUtils::login(new CosignLogin($login, $krbpwd), $connection);
             $login = null;
             $krbpwd = null;
         } else {
             if ($cosignCookie !== null) {
                 $loggedIn = FajrUtils::login(new AIS2CookieLogin($cosignCookie), $connection);
                 $cosignCookie = null;
             } else {
                 $loggedIn = FajrUtils::isLoggedIn();
             }
         }
         if ($loggedIn) {
             DisplayManager::addContent('<div class=\'logout\'><a class="button negative" href="' . FajrUtils::linkUrl(array('logout' => true)) . '">
     <img src="images/door_in.png" alt=""/>Odhlásiť</a></div>');
             $adminStudia = new VSES017\AdministraciaStudiaScreen($trace, $simpleConnection);
             if (Input::get('studium') === null) {
                 Input::set('studium', 0);
             }
             $zoznamStudii = $adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:"));
             $zoznamStudiiTable = new Table(TableDefinitions::zoznamStudii(), 'studium', array('tab' => Input::get('tab')));
             $zoznamStudiiTable->addRows($zoznamStudii->getData());
             $zoznamStudiiTable->setOption('selected_key', Input::get('studium'));
             $zoznamStudiiTable->setOption('collapsed', true);
             $zoznamStudiiCollapsible = new Collapsible(new HtmlHeader('Zoznam štúdií'), $zoznamStudiiTable, true);
             DisplayManager::addContent($zoznamStudiiCollapsible->getHtml());
             $zapisneListy = $adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), Input::get('studium'));
             $zapisneListyTable = new Table(TableDefinitions::zoznamZapisnychListov(), 'list', array('studium' => Input::get('studium'), 'tab' => Input::get('tab')));
             if (Input::get('list') === null) {
                 $tmp = $zapisneListy->getData();
                 $lastList = end($tmp);
                 Input::set('list', $lastList['index']);
             }
             $zapisneListyTable->addRows($zapisneListy->getData());
             $zapisneListyTable->setOption('selected_key', Input::get('list'));
             $zapisneListyTable->setOption('collapsed', true);
             $zapisneListyCollapsible = new Collapsible(new HtmlHeader('Zoznam zápisných listov'), $zapisneListyTable, true);
             DisplayManager::addContent($zapisneListyCollapsible->getHtml());
             $terminyHodnotenia = new VSES017\TerminyHodnoteniaScreen($trace, $simpleConnection, $adminStudia->getIdZapisnyList($trace, Input::get('list')), $adminStudia->getIdStudium($trace, Input::get('list')));
             if (Input::get('tab') === null) {
                 Input::set('tab', 'TerminyHodnotenia');
             }
             $tabs = new TabManager('tab', array('studium' => Input::get('studium'), 'list' => Input::get('list')));
             // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne
             // objekty, ktore v konstruktore robia requesty
             $hodnoteniaScreen = new VSES017\HodnoteniaPriemeryScreen($trace, $simpleConnection, $adminStudia->getIdZapisnyList($trace, Input::get('list')));
             $tabs->addTab('TerminyHodnotenia', 'Moje skúšky', new MojeTerminyHodnoteniaCallback($trace, $terminyHodnotenia, $hodnoteniaScreen));
             $tabs->addTab('ZapisSkusok', 'Prihlásenie na skúšky', new ZoznamTerminovCallback($trace, $terminyHodnotenia, $hodnoteniaScreen));
             $tabs->addTab('ZapisnyList', 'Zápisný list', new ZapisanePredmetyCallback($trace, $terminyHodnotenia));
             $tabs->addTab('Hodnotenia', 'Hodnotenia/Priemery', new HodnoteniaCallback($trace, $hodnoteniaScreen));
             $tabs->setActive(Input::get('tab'));
             DisplayManager::addContent($tabs->getHtml());
             $version = '<div>Fajr verzia ' . hescape(Version::getVersionString()) . '</div>';
             DisplayManager::addContent($version);
             $statistics = "<div> Fajr made " . $statsConnection->getTotalCount() . " requests and downloaded " . $rawStatsConnection->getTotalSize() . " bytes (" . $statsConnection->getTotalSize() . " bytes uncompressed) of data from AIS2 in " . sprintf("%.3f", $statsConnection->getTotalTime()) . " seconds. It took " . sprintf("%.3f", $timer->getElapsedTime()) . " seconds to generate this page.</div>";
             DisplayManager::addContent($statistics);
         } else {
             DisplayManager::addContent('loginBox', true);
             DisplayManager::addContent('warnings', true);
             DisplayManager::addContent('terms', true);
             DisplayManager::addContent('credits', true);
             $version = "<div class='version prepend-1 span-21 last increase-line-height'>\n<strong>Verzia fajru:</strong> \n";
             $version .= hescape(Version::getVersionString());
             $version .= '</div>';
             DisplayManager::addContent($version);
             DisplayManager::addContent(Version::getChangelog(), false);
         }
     } catch (AIS2LoginException $e) {
         if ($connection) {
             FajrUtils::logout($connection);
         }
         DisplayManager::addException($e);
     } catch (Exception $e) {
         DisplayManager::addException($e);
     }
     DisplayManager::setBase(hescape(FajrUtils::basePath()));
     $trace->tlog("everything done, generating html");
     if (FajrConfig::get('Debug.Trace') === true) {
         $traceHtml = $trace->getHtml();
         DisplayManager::addContent('<div class="span-24">' . $traceHtml . '<div> Trace size:' . sprintf("%.2f", strlen($traceHtml) / 1024.0 / 1024.0) . ' MB</div></div>');
     }
     echo DisplayManager::display();
 }
コード例 #4
0
 /**
  * @returns float total network IO time spent in seconds
  */
 public function getTotalRequestTime()
 {
     return $this->finalConnection->getTotalTime();
 }