/** * * @return boolean */ public static function flush() { if (empty(static::$server['ip']) || empty(static::$server['port']) || empty(static::$server['protocol'])) { return false; } $socket = socket_create(static::$ipType, static::$server['protocol'] == SOL_TCP ? SOCK_STREAM : SOCK_DGRAM, static::$server['protocol']); while ($element = array_shift(static::$pool)) { if (is_a($element, 'MrAudioGuy\\Syslog\\Block')) { $message = $element->logBlock(); if (static::$server['protocol'] == SOL_TCP) { if (!@socket_connect($socket, static::$server['ip'], static::$server['port'])) { array_unshift(static::$pool, $element); socket_close($socket); return false; } } if (!socket_sendto($socket, $message, strlen($message), 0, static::$server["ip"], static::$server["port"])) { array_unshift(static::$pool, $element); socket_close($socket); return false; } } } socket_close($socket); static::$pool = null; return true; }
/** * Add connection pool * * @param ConnectionPool $pool */ public static function setPool(ConnectionPool $pool) { static::$pool = $pool; static::$connection_name = $pool->getDefaultConnectionName(); }