Exemplo n.º 1
0
 /**
  * Sends a Message over this transport
  *
  * @param Message $message
  *
  * @return int the number of TCP packets sent
  */
 public function send(Message $message)
 {
     $rawMessage = $this->getMessageEncoder()->encode($message) . "";
     // send message in one packet
     $this->socketClient->write($rawMessage);
     return 1;
 }
Exemplo n.º 2
0
 /**
  * @return string
  */
 private function readResponseHeaders()
 {
     $chunkSize = 1024;
     // number of bytes to read at once
     $delimiter = "\r\n\r\n";
     // delimiter between headers and rsponse
     $response = "";
     do {
         $chunk = $this->socketClient->read($chunkSize);
         $response .= $chunk;
     } while (false === strpos($chunk, $delimiter) && strlen($chunk) > 0);
     $elements = explode($delimiter, $response, 2);
     return $elements[0];
 }
Exemplo n.º 3
0
 /**
 * Sends given string in multiple chunks
 *
 * @param string $rawMessage
 * @return int
 *
 * @throws RuntimeException on too large messages which would exceed the 
                            maximum number of possible chunks
 */
 protected function sendMessageInChunks($rawMessage)
 {
     // split to chunks
     $chunks = str_split($rawMessage, $this->chunkSize);
     $numChunks = count($chunks);
     if ($numChunks > self::CHUNK_MAX_COUNT) {
         throw new RuntimeException(sprintf("Message is to big. Chunk count exceeds %d", self::CHUNK_MAX_COUNT));
     }
     // generate a random 8byte-message-id
     $messageId = substr(md5(uniqid(), true), 0, 8);
     // send chunks with a correct chunk-header
     // @link http://graylog2.org/gelf#specs
     foreach ($chunks as $idx => $chunk) {
         $data = self::CHUNK_GELF_ID . $messageId . pack('CC', $idx, $numChunks) . $chunk;
         $this->socketClient->write($data);
     }
     return $numChunks;
 }
Exemplo n.º 4
0
 /**
  * Returns the connect-timeout
  *
  * @return int
  */
 public function getConnectTimeout()
 {
     return $this->socketClient->getConnectTimeout();
 }
Exemplo n.º 5
0
 public function testDestructorWithSocket()
 {
     $this->socketClient->getSocket();
     unset($this->socketClient);
 }