*/ class FluentdTcpStorage extends AbstractRequestLogStorage { const OPTION_HOST = 'host'; const OPTION_PORT = 'port'; const OPTION_DELIMITER = 'delimiter'; /** * @var resource */ private $resource; /** * Connect to the server and return the open socket * * @return resource * @throws RequestLogException */ public function getSocket() { if (is_null($this->resource)) { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { throw new RequestLogException('Unable to open TCP socket: '.socket_strerror(socket_last_error())); } $success = socket_connect($socket, $this->getOption(self::OPTION_HOST), $this->getOption(self::OPTION_PORT)); if ($success === false) { throw new RequestLogException('Unable to connect to host: '.socket_strerror(socket_last_error())); } $this->resource = $socket; } return $this->resource; } /** * (non-PHPdoc) * @see \oat\taoEventLog\model\requestLog\RequestLogStorageWritable::log() */ public function log(RequestInterface $request, User $user) { $message = json_encode($this->prepareData($request, $user)); $message .= $this->hasOption(self::OPTION_DELIMITER) ? $this->getOption(self::OPTION_DELIMITER) : ''; while (!empty($message)) { $send = socket_write($this->getSocket(),$message, strlen($message)); if ($send != strlen($message)) { throw new RequestLogException('Unable to send msg: '.socket_strerror(socket_last_error())); } $message = substr($message, $send); } } }