* @package generis */ class common_log_UDPAppender extends common_log_BaseAppender { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- /** * Short description of attribute host * * @access public * @var string */ public $host = '127.0.0.1'; /** * Short description of attribute port * * @access public * @var int */ public $port = 5775; /** * Short description of attribute resource * * @access public * @var resource */ public $resource = null; // --- OPERATIONS --- /** * Short description of method init * * @access public * @author Joel Bout, * @param array configuration * @return boolean */ public function init($configuration) { $returnValue = (bool) false; if (isset($configuration['host'])) { $this->host = $configuration['host']; } if (isset($configuration['port'])) { $this->port = $configuration['port']; } $returnValue = parent::init($configuration); return (bool) $returnValue; } /** * Short description of method doLog * * @access public * @author Joel Bout, * @param Item item * @return mixed */ public function doLog(common_log_Item $item) { if (is_null($this->resource)) { $this->resource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_set_nonblock($this->resource); } if ($this->resource !== false) { $message = json_encode([ 's' => $item->getSeverity(), 'd' => $item->getDescription(), 'p' => $this->prefix, 't' => $item->getTags(), 'f' => $item->getCallerFile(), 'l' => $item->getCallerLine(), 'b' => $item->getBacktrace() ]); @socket_sendto($this->resource, $message, strlen($message), 0, $this->host, $this->port); //ignore errors, socket might already be closed because php is shutting down } } /** * Short description of method __destruct * * @access public * @author Joel Bout, * @return mixed */ public function __destruct() { // don't close since we might still need it /* if (!is_null($this->resource) && $this->resource !== false) { socket_close($this->resource); } parent::__destruct(); */ } }