Permalink
Browse files

support for different compression types

  • Loading branch information...
1 parent 5800d3b commit 447ba6b313383dca7081886f99f282b9393ae413 Renaud Drousies committed Dec 16, 2011
Showing with 15 additions and 2 deletions.
  1. +15 −2 gelf.php
View
@@ -6,18 +6,31 @@ class GELFMessage {
private $graylogHostname;
private $graylogPort;
+ private $compressFunction;
private $maxChunkSize;
private $data;
- public function __construct($graylogHostname, $graylogPort, $maxChunkSize = 'WAN')
+ public function __construct($graylogHostname, $graylogPort, $maxChunkSize = 'WAN', $compression = 'zlib')
{
if (!is_numeric($graylogPort)) {
throw new Exception("Port must be numeric");
}
$this->graylogHostname = $graylogHostname;
$this->graylogPort = $graylogPort;
+
+ switch ($compression) {
+ case 'gzip':
+ $this->compressFunction = 'gzencode';
+ break;
+ case 'deflate':
+ $this->compressFunction = 'gzdeflate';
+ break;
+ default:
+ $this->compressFunction = 'gzcompress';
+ }
+
switch ($maxChunkSize) {
case 'WAN':
$this->maxChunkSize = 1420;
@@ -52,7 +65,7 @@ public function send()
}
// Convert data array to JSON and GZIP.
- $gzippedJsonData = gzcompress(json_encode($this->data));
+ $gzippedJsonData = call_user_func($this->compressFunction, json_encode($this->data));
$sock = stream_socket_client('udp://' . gethostbyname($this->graylogHostname) .':' . $this->graylogPort);

0 comments on commit 447ba6b

Please sign in to comment.