Skip to content

fix: increase batch payload size limit from 32KB#110

Merged
cat-ph merged 3 commits intomasterfrom
fix/increase-batch-size-limit
Mar 30, 2026
Merged

fix: increase batch payload size limit from 32KB#110
cat-ph merged 3 commits intomasterfrom
fix/increase-batch-size-limit

Conversation

@cat-ph
Copy link
Copy Markdown
Contributor

@cat-ph cat-ph commented Mar 28, 2026

Summary

  • The PHP SDK enforces a 6-year-old 32KB batch payload size limit across all three consumers (ForkCurl, LibCurl, Socket), silently dropping batches that exceed it
  • Any non-trivial batch with feature flags or rich properties can hit this easily
  • The PostHog /batch/ endpoint accepts up to 20MB
  • The Python SDK uses 5MB, Ruby uses 500KB, JS has no client-side limit
  • This bumps the PHP limit to 5MB to match Python

Changes

  • lib/Consumer/ForkCurl.php - 32 * 1024 -> 1 * 1024 * 1024
  • lib/Consumer/LibCurl.php - same
  • lib/Consumer/Socket.php - same

Test plan

  • Existing tests pass (no tests assert the 32KB limit on master)
  • Verified >32KB batch (~55KB) sends successfully against local PostHog instance

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.
@cat-ph
Copy link
Copy Markdown
Contributor Author

cat-ph commented Mar 28, 2026

I think this is probably a simpler solution for #31 than #82 and #83 since 5mb gives quite a bit more leeway than 5kb, I tested this against localhost with >32kb and it seems to go through just fine 🤔

@cat-ph cat-ph requested review from a team, ablaszkiewicz and hpouillot March 28, 2026 11:31
@cat-ph cat-ph changed the title fix: increase batch payload size limit from 32KB to 5MB fix: increase batch payload size limit from 32KB Mar 30, 2026
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 / 1024) . "KB";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self::MAX_BATCH_PAYLOAD_SIZE / 1024
can could also be a const, no need to divide every single time

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for libcurl, socket, etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I thought about it too, forgot arithmetic / concatenation works with const initializers in PHP too 😆 wanted to go the full "human readable stringification" route but not worth the extra logic currently; keeping it a separate const is 👍, updated

@cat-ph cat-ph added the release label Mar 30, 2026
@cat-ph cat-ph merged commit d4fb77c into master Mar 30, 2026
15 checks passed
@cat-ph cat-ph deleted the fix/increase-batch-size-limit branch March 30, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants