public function testLog() { Log::setLevel('ALL'); Conf::set('log_delayed', true); Conf::set('log_handlers', array('\\photon\\log\\NullBackend')); $message = 'dummy message'; $i = 0; Log::plog($message); $i++; $this->assertEquals($i, count(Log::$stack)); Log::debug($message); $i++; $this->assertEquals($i, count(Log::$stack)); Log::info($message); $i++; $this->assertEquals($i, count(Log::$stack)); Log::perf($message); $i++; $this->assertEquals($i, count(Log::$stack)); Log::event($message); $i++; $this->assertEquals($i, count(Log::$stack)); Log::warn($message); $i++; $this->assertEquals($i, count(Log::$stack)); Log::error($message); $i++; $this->assertEquals($i, count(Log::$stack)); Log::fatal($message); $i++; $this->assertEquals($i, count(Log::$stack)); FileBackend::$return = true; Log::flush(); $this->assertEquals(0, count(Log::$stack)); FileBackend::$return = false; Log::flush(); $this->assertEquals(0, count(Log::$stack)); Log::flush(); $this->assertEquals(0, count(Log::$stack)); Conf::set('log_delayed', false); Log::info($message); $this->assertEquals(0, count(Log::$stack)); }
public function registerSignals() { if (!pcntl_signal(\SIGTERM, array('\\photon\\server\\Server', 'signalHandler'))) { Log::fatal('Cannot install the SIGTERM signal handler.'); die(1); } }
public function testLog() { Log::setLevel('ALL'); Log::info('PHPUnit is running'); Log::info('All looks good !'); }
/** * The definition to get a connection is: * * Required: * * - server (mapped to host in the connection string); * - database (mapped to dbname in the connection string); * * Optional: * * - user; * - hostaddr; * - port; * - password; * - connect_timeout; * - options; * - sslmode; * - service. * * You can read more about it here: http://www.php.net/pg_connect */ public static function get($def) { $user = null; $password = null; $allowed_cfg = array('host', 'dbname', 'user', 'hostaddr', 'port', 'password', 'connect_timeout', 'options', 'sslmode', 'service'); $cfgs = array(); $opts = array(); foreach ($def as $key => $value) { if ('engine' === $key) { continue; } $key = str_replace(array('server', 'database'), array('host', 'dbname'), $key); if ('user' == $key) { $user = $value; } elseif ('password' == $key) { $password = $value; } elseif (in_array($key, $allowed_cfg)) { $cfgs[] = $key . '=' . $value; } else { $opts[$key] = $value; } } Log::debug(array('photon.db.PostgreSQL.get', $cfgs, $user, $password, $opts)); return new \PDO('pgsql:' . implode(';', $cfgs), $user, $password, $opts); }
<?php // Set the initial log level \photon\log\Log::setLevel('INFO'); return array('debug' => true, 'secret_key' => 'A very long secret key to sign cookie', 'base_urls' => '', 'urls' => include 'urls.php', 'template_folders' => array(__DIR__ . '/HelloWorld/templates'), 'middleware_classes' => array('photon\\middleware\\Gzip'));
/** * Call the view found by self::match. * * The called view can throw an exception. This is fine and * normal. * * @param $req Photon request * @param $ctl The url definition matching the request * @param $matches The matches found by preg_match * @return mixed Response or None */ public static function send($req, $ctl, $match) { Log::debug(array('photon.dispatch.send', $req->uuid, array($ctl, $match))); $req->view = array($ctl, $match); if (is_array($ctl['view'])) { list($mn, $mv) = $ctl['view']; $m = new $mn(); if (isset($m->{$mv . '_precond'})) { // Preconditions to respects. A precondition must return // true or a response object. $preconds = $m->{$mv . '_precond'}; foreach ($preconds as $precond) { $res = call_user_func_array($precond, array(&$req)); if ($res !== true) { return $res; } } } if (!isset($ctl['params'])) { return $m->{$mv}($req, $match); } else { return $m->{$mv}($req, $match, $ctl['params']); } } else { // simple callable function $v = $ctl['view']; if (!isset($ctl['params'])) { return $v($req, $match); } else { return $v($req, $match, $ctl['params']); } } }
public function loop() { // Execute the back ground task, only one time per seconds static $lastRefresh = 0; $now = time(); if ($now == $lastRefresh) { return; } $lastRefresh = $now; Log::debug('Connections actives to mongrel2: ' . count($this->connections)); foreach ($this->connections as $connectionIndex => $connection) { Log::debug('#' . $connectionIndex . ' Jobs: ' . count($this->jobs[$connectionIndex])); $this->_loop($connectionIndex, $connection, $this->jobs[$connectionIndex]); } }
/** * Output a message. */ public function info($message, $eol = PHP_EOL) { if (!$this->daemon) { echo $message . $eol; } else { Log::info($message); } }
public function registerSignals() { if (!pcntl_signal(SIGTERM, array('\\photon\\task\\BaseTask', 'signalHandler'))) { Log::fatal('Cannot install the SIGTERM signal handler.'); exit(1); } }