diff --git a/lib/Consumer/ForkCurl.php b/lib/Consumer/ForkCurl.php index 5a16779..13edc11 100644 --- a/lib/Consumer/ForkCurl.php +++ b/lib/Consumer/ForkCurl.php @@ -74,10 +74,9 @@ public function flushBatch($messages) $cmd .= " '" . $url . "'"; - // Verify message size is below than 32KB - if (strlen($payload) >= 32 * 1024) { + if (strlen($payload) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than 32KB"; + $msg = "Message size is larger than " . self::MAX_BATCH_PAYLOAD_SIZE_HUMAN; error_log("[PostHog][" . $this->type . "] " . $msg); } diff --git a/lib/Consumer/LibCurl.php b/lib/Consumer/LibCurl.php index 973e960..360cb9a 100644 --- a/lib/Consumer/LibCurl.php +++ b/lib/Consumer/LibCurl.php @@ -56,10 +56,9 @@ public function flushBatch($messages) $body = $this->payload($messages); $payload = json_encode($body); - // Verify message size is below than 32KB - if (strlen($payload) >= 32 * 1024) { + if (strlen($payload) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than 32KB"; + $msg = "Message size is larger than " . self::MAX_BATCH_PAYLOAD_SIZE_HUMAN; error_log("[PostHog][" . $this->type . "] " . $msg); } diff --git a/lib/Consumer/Socket.php b/lib/Consumer/Socket.php index 11e11c5..8173fde 100644 --- a/lib/Consumer/Socket.php +++ b/lib/Consumer/Socket.php @@ -200,10 +200,9 @@ private function createBody($host, $content) $req .= "\r\n"; $req .= $content; - // Verify message size is below than 32KB - if (strlen($req) >= 32 * 1024) { + if (strlen($req) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than 32KB"; + $msg = "Message size is larger than " . self::MAX_BATCH_PAYLOAD_SIZE_HUMAN; error_log("[PostHog][" . $this->type . "] " . $msg); } diff --git a/lib/QueueConsumer.php b/lib/QueueConsumer.php index 354e12c..0eaec96 100644 --- a/lib/QueueConsumer.php +++ b/lib/QueueConsumer.php @@ -4,6 +4,9 @@ abstract class QueueConsumer extends Consumer { + protected const MAX_BATCH_PAYLOAD_SIZE = 1024 * 1024; // 1MB + protected const MAX_BATCH_PAYLOAD_SIZE_HUMAN = (self::MAX_BATCH_PAYLOAD_SIZE / 1024) . 'KB'; + protected $type = "QueueConsumer"; protected $queue;