From 48eb246bd905f3356bb9eabbe0424e3531ceee46 Mon Sep 17 00:00:00 2001 From: Catalin Irimie Date: Sat, 28 Mar 2026 03:27:38 +0200 Subject: [PATCH 1/3] fix: increase batch payload size limit from 32KB to 5MB The 32KB limit was inherited from 6yo library and is far too restrictive. The PostHog /batch/ endpoint accepts up to 20MB, and the Python SDK already uses a 5MB limit. --- lib/Consumer/ForkCurl.php | 6 +++--- lib/Consumer/LibCurl.php | 6 +++--- lib/Consumer/Socket.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Consumer/ForkCurl.php b/lib/Consumer/ForkCurl.php index 5a16779..dee0b1e 100644 --- a/lib/Consumer/ForkCurl.php +++ b/lib/Consumer/ForkCurl.php @@ -74,10 +74,10 @@ public function flushBatch($messages) $cmd .= " '" . $url . "'"; - // Verify message size is below than 32KB - if (strlen($payload) >= 32 * 1024) { + // Verify message size is below than 5MB + if (strlen($payload) >= 5 * 1024 * 1024) { if ($this->debug()) { - $msg = "Message size is larger than 32KB"; + $msg = "Message size is larger than 5MB"; error_log("[PostHog][" . $this->type . "] " . $msg); } diff --git a/lib/Consumer/LibCurl.php b/lib/Consumer/LibCurl.php index 973e960..7600843 100644 --- a/lib/Consumer/LibCurl.php +++ b/lib/Consumer/LibCurl.php @@ -56,10 +56,10 @@ public function flushBatch($messages) $body = $this->payload($messages); $payload = json_encode($body); - // Verify message size is below than 32KB - if (strlen($payload) >= 32 * 1024) { + // Verify message size is below than 5MB + if (strlen($payload) >= 5 * 1024 * 1024) { if ($this->debug()) { - $msg = "Message size is larger than 32KB"; + $msg = "Message size is larger than 5MB"; error_log("[PostHog][" . $this->type . "] " . $msg); } diff --git a/lib/Consumer/Socket.php b/lib/Consumer/Socket.php index 11e11c5..b7f56a4 100644 --- a/lib/Consumer/Socket.php +++ b/lib/Consumer/Socket.php @@ -200,10 +200,10 @@ private function createBody($host, $content) $req .= "\r\n"; $req .= $content; - // Verify message size is below than 32KB - if (strlen($req) >= 32 * 1024) { + // Verify message size is below than 5MB + if (strlen($req) >= 5 * 1024 * 1024) { if ($this->debug()) { - $msg = "Message size is larger than 32KB"; + $msg = "Message size is larger than 5MB"; error_log("[PostHog][" . $this->type . "] " . $msg); } From e217045170c17e43f83f023fc47b5b0cd6897aa9 Mon Sep 17 00:00:00 2001 From: Catalin Irimie Date: Mon, 30 Mar 2026 13:59:19 +0300 Subject: [PATCH 2/3] chore: move to 1MB size + shared const --- lib/Consumer/ForkCurl.php | 5 ++--- lib/Consumer/LibCurl.php | 5 ++--- lib/Consumer/Socket.php | 5 ++--- lib/QueueConsumer.php | 2 ++ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/Consumer/ForkCurl.php b/lib/Consumer/ForkCurl.php index dee0b1e..202c3d8 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 5MB - if (strlen($payload) >= 5 * 1024 * 1024) { + if (strlen($payload) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than 5MB"; + $msg = "Message size is larger than " . (self::MAX_BATCH_PAYLOAD_SIZE / 1024) . "KB"; error_log("[PostHog][" . $this->type . "] " . $msg); } diff --git a/lib/Consumer/LibCurl.php b/lib/Consumer/LibCurl.php index 7600843..642e2af 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 5MB - if (strlen($payload) >= 5 * 1024 * 1024) { + if (strlen($payload) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than 5MB"; + $msg = "Message size is larger than " . (self::MAX_BATCH_PAYLOAD_SIZE / 1024) . "KB"; error_log("[PostHog][" . $this->type . "] " . $msg); } diff --git a/lib/Consumer/Socket.php b/lib/Consumer/Socket.php index b7f56a4..95f1419 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 5MB - if (strlen($req) >= 5 * 1024 * 1024) { + if (strlen($req) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than 5MB"; + $msg = "Message size is larger than " . (self::MAX_BATCH_PAYLOAD_SIZE / 1024) . "KB"; error_log("[PostHog][" . $this->type . "] " . $msg); } diff --git a/lib/QueueConsumer.php b/lib/QueueConsumer.php index 354e12c..99fc47c 100644 --- a/lib/QueueConsumer.php +++ b/lib/QueueConsumer.php @@ -4,6 +4,8 @@ abstract class QueueConsumer extends Consumer { + protected const MAX_BATCH_PAYLOAD_SIZE = 1024 * 1024; // 1MB + protected $type = "QueueConsumer"; protected $queue; From 58da3f87bc91d936979ed0e8dd20a9103b05bb15 Mon Sep 17 00:00:00 2001 From: Catalin Irimie Date: Mon, 30 Mar 2026 14:19:51 +0300 Subject: [PATCH 3/3] chore: shared human readable size const --- lib/Consumer/ForkCurl.php | 2 +- lib/Consumer/LibCurl.php | 2 +- lib/Consumer/Socket.php | 2 +- lib/QueueConsumer.php | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Consumer/ForkCurl.php b/lib/Consumer/ForkCurl.php index 202c3d8..13edc11 100644 --- a/lib/Consumer/ForkCurl.php +++ b/lib/Consumer/ForkCurl.php @@ -76,7 +76,7 @@ public function flushBatch($messages) if (strlen($payload) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than " . (self::MAX_BATCH_PAYLOAD_SIZE / 1024) . "KB"; + $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 642e2af..360cb9a 100644 --- a/lib/Consumer/LibCurl.php +++ b/lib/Consumer/LibCurl.php @@ -58,7 +58,7 @@ public function flushBatch($messages) if (strlen($payload) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than " . (self::MAX_BATCH_PAYLOAD_SIZE / 1024) . "KB"; + $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 95f1419..8173fde 100644 --- a/lib/Consumer/Socket.php +++ b/lib/Consumer/Socket.php @@ -202,7 +202,7 @@ private function createBody($host, $content) if (strlen($req) >= self::MAX_BATCH_PAYLOAD_SIZE) { if ($this->debug()) { - $msg = "Message size is larger than " . (self::MAX_BATCH_PAYLOAD_SIZE / 1024) . "KB"; + $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 99fc47c..0eaec96 100644 --- a/lib/QueueConsumer.php +++ b/lib/QueueConsumer.php @@ -5,6 +5,7 @@ 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";