posthog / posthog-php
PostHog PHP Library
4.2.2
2026-04-21 14:49 UTC
Requires
- php: >=8.2
- ext-json: *
- symfony/clock: ^6.2|^7.0|^8.0
Requires (Dev)
- phpunit/phpunit: ^11.0
- squizlabs/php_codesniffer: ^3.7
- dev-main
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.0
- 3.4.0
- 3.3.5
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.1.1
- 2.1.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- dev-chore/release-workflow-push-main
- dev-feat/semver-targeting
- dev-matheus-vb/fix-failed-flag-overwrite
- dev-feat/get-feature-flag-result
- dev-ci/notify-release-rejected
- dev-vdekrijger-add-github-releaser-app
- dev-vdekrijger-bump-to-php85
- dev-fix/send-feature-flags
- dev-haacked/etag-support
- dev-cut-releases-when-deploying-new-version-php
- dev-feat/publish-evaluated-at-events
- dev-posthog/task-PHA-102
- dev-posthog/task-PHA-104
- dev-posthog/task-PHA-103
- dev-posthog/task-MCP-6
- dev-posthog/task-PHA-100
- dev-posthog/task-PHA-99
- dev-posthog/task-PHA-89
- dev-haacked/static-cohort-local-eval-fix
- dev-andyzzhao/dont-sort-variant-overrides
- dev-feat/transactional-queue-prevent-data-loss
- dev-fix/handle-flushing-events-with-32kb-limit
- dev-haacked/ignore-flag-dependencies
- dev-chore/bump-version
- dev-chore/use-flags
- dev-fix/try-this-instead
- dev-feat/feature-flag-payloads
- dev-fix-makefile-version
- dev-non-blocking-lib-curl
- dev-pnctl-fork-async
- dev-fix-bool-match
- dev-cohort-local-eval
- dev-add-flag-timeout
- dev-update-names
- dev-local-prop
- dev-prop-matching
- dev-neilkakkar-patch-1
- dev-fix-decide-v2
- dev-alisqi/master
- dev-fix-bug
- dev-groups-fix
- dev-timeout-configurable
- dev-php-unit/cs-version
- dev-update-version-3.0.1
- dev-ff-overrides
- dev-update-history-3.0.0
- dev-ff-remove-defaultvalue
- dev-turbo
- dev-group-analytics-flags
- dev-group-analytics-support
- dev-handle-host
- dev-feature-flags
- dev-zidsa/master
This package is auto-updated.
Last update: 2026-04-23 22:04:03 UTC
README
Please see the main PostHog docs.
Specifically, the PHP integration details.
Features
- ✅ Event capture and user identification
- ✅ Error tracking with manual exception capture
- ✅ Opt-in automatic PHP exception, error, and fatal shutdown capture
- ✅ Feature flag local evaluation
- ✅ Feature flag dependencies (new!) - Create conditional flags based on other flags
- ✅ Multivariate flags and payloads
- ✅ Group analytics
- ✅ Comprehensive test coverage
Quick Start
- Copy
.env.exampleto.envand add your PostHog credentials - Run
php example.phpto see interactive examples of all features
Error Tracking
Manual exception capture:
PostHog::captureException($exception, 'user-123', [ '$current_url' => 'https://example.com/settings', ]);
Opt-in automatic capture from the core SDK:
PostHog::init('phc_xxx', [ 'error_tracking' => [ 'enabled' => true, 'capture_errors' => true, 'excluded_exceptions' => [ \InvalidArgumentException::class, ], 'context_provider' => static function (array $payload): array { return [ 'distinctId' => $_SESSION['user_id'] ?? null, 'properties' => [ '$current_url' => $_SERVER['REQUEST_URI'] ?? null, ], ]; }, ], ]);
Auto error tracking is off by default. When enabled, the SDK chains existing exception and error handlers instead of replacing app behavior.
Questions?
Join our Slack community.
Contributing
See CONTRIBUTING.md for local setup and test instructions.
Releasing
See RELEASING.md.