Exemplo n.º 1
0
 /**
  * @param $level
  * @param $message
  * @param array $context
  * @throws \Exception
  */
 private function send($level, $message, array $context)
 {
     $msg = new Zmsg($this->socket);
     if (sizeof($context) > 0) {
         $msg->wrap(json_encode($context));
         $msg->wrap(ZLogger::CONTEXT_DELIMITER);
     }
     $msg->wrap($message);
     $msg->wrap($level);
     $msg->wrap(sprintf("%.0f", microtime(1) * 1000));
     $msg->wrap($this->logName);
     if ($this->verbose) {
         print_r("I: send msg");
         echo PHP_EOL, $msg, PHP_EOL;
     }
     $msg->send(true);
 }
Exemplo n.º 2
0
 public function testMultiPartMessage()
 {
     $zmsgo = new Zmsg(self::$outputSocket);
     $zmsgo->body_set("Hello");
     $zmsgo->wrap("address1", "");
     $zmsgo->wrap("address2");
     $this->assertEquals($zmsgo->parts(), 4);
     $zmsgo->send();
     $zmsgi = new Zmsg(self::$inputSocket);
     $zmsgi->recv();
     $this->assertEquals($zmsgi->parts(), 5);
     $zmsgi->unwrap();
     $this->assertEquals($zmsgi->unwrap(), "address2");
     $zmsgi->body_fmt("%s%s", 'W', "orld");
     $this->assertEquals($zmsgi->body(), "World");
     // Pull off address 1, check that empty part was dropped
     $zmsgi->unwrap();
     $this->assertEquals($zmsgi->parts(), 1);
     // Check that message body was correctly modified
     $part = $zmsgi->pop();
     $this->assertEquals($part, "World");
     $this->assertEquals($zmsgi->parts(), 0);
 }