Beispiel #1
0
 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));
 }
Beispiel #2
0
 /**
  * Must be started when already running as daemon.
  */
 public function start()
 {
     $this->registerSignals();
     // For SIGTERM handling
     $poll = new \ZMQPoll();
     foreach ($this->connections as $connection) {
         $connection->connect();
         $poll->add($connection->pull_socket, \ZMQ::POLL_IN);
     }
     // We are using polling to not block indefinitely and be able
     // to process the SIGTERM signal. The poll timeout is .5 second.
     $timeout = 500;
     $to_read = $to_write = array();
     $gc = gc_enabled();
     $i = 0;
     while (true) {
         $events = 0;
         try {
             $events = $poll->poll($to_read, $to_write, $timeout);
             $errors = $poll->getLastErrors();
             if (count($errors) > 0) {
                 foreach ($errors as $error) {
                     Log::error('Error polling object: ' . $error);
                 }
             }
         } catch (\ZMQPollException $e) {
             Log::fatal('Poll failed: ' . $e->getMessage());
             return 1;
         }
         if ($events > 0) {
             foreach ($to_read as $r) {
                 foreach ($this->connections as $connection) {
                     if ($connection->pull_socket === $r) {
                         $this->processRequest($connection);
                         break;
                     }
                 }
                 $i++;
             }
         }
         pcntl_signal_dispatch();
         if ($gc && 500 < $i) {
             $collected = gc_collect_cycles();
             Log::debug(array('photon.server.start', 'collected_cycles', $collected));
             $i = 0;
         }
     }
 }
Beispiel #3
0
 public function run()
 {
     $to_write = array();
     $to_read = array();
     while (true) {
         $events = 0;
         try {
             // We poll and wait a maximum of 200ms.
             $events = $this->poll->poll($to_read, $to_write, 200);
             $errors = $this->poll->getLastErrors();
             if (count($errors) > 0) {
                 foreach ($errors as $error) {
                     Log::error('Error polling object: ' . $error);
                 }
             }
         } catch (\ZMQPollException $e) {
             Log::fatal('Poll failed: ' . $e->getMessage());
             return 1;
         }
         if ($events > 0) {
             foreach ($to_read as $r) {
                 $this->work($r);
             }
         }
         $this->loop();
         pcntl_signal_dispatch();
         clearstatcache();
     }
 }