Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'verify_batch_events_request=>false' #70

Merged
merged 2 commits into from
Mar 11, 2025

Conversation

danielbachhuber
Copy link
Contributor

@danielbachhuber danielbachhuber commented Mar 10, 2025

See https://posthog.slack.com/archives/C03P7NL6RMW/p1741208127179239
See https://posthog.slack.com/archives/C07L8G1HVQR/p1741196816062289

Changes

Adds support for a 'verify_batch_events_request' => false setting when initializing PostHog. This will allow batch events requests to be sent in a non-blocking manner when using the LibCurl default transport.

Testing

To test, add some delay to the deprecated capture endpoint on your local PostHog install:

diff --git a/posthog/api/capture.py b/posthog/api/capture.py
index 8a1397c113..c6fe4cdf06 100644
--- a/posthog/api/capture.py
+++ b/posthog/api/capture.py
@@ -405,6 +405,8 @@ def lib_version_from_query_params(request) -> str:
 def get_event(request):
     structlog.contextvars.unbind_contextvars("team_id")
 
+    time.sleep(20)
+
     # handle cors request
     if request.method == "OPTIONS":
         return cors_response(request, JsonResponse({"status": 1}))

Then, download this test script to somewhere you can run PHP and apply an API key:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use PostHog\PostHog;

const POSTHOG_API_KEY = "your_api_key";

PostHog::init(
    POSTHOG_API_KEY,
    array('host' => 'http://localhost:8000', 'ssl' => false, 'verify_batch_events_request' => false),
);

$distinctId = uniqid();

PostHog::capture(array(
    'distinctId' => $distinctId,
    'event' => 'php-test user signed up - ' . $distinctId
));
error_log('captured ' . $distinctId);

With 'verify_batch_events_request' => false, the test script should execute right away and your event should appear in your activity log.

With 'verify_batch_events_request' => true, the test script should take ~20s to execute and your event should appear in your activity log.

@danielbachhuber danielbachhuber merged commit 30b1bd3 into master Mar 11, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants