You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PHP SDK captures stack traces with file names, line numbers, and function names, but does not yet support source context (displaying the surrounding lines of code in the error tracking UI). Symbol set uploads for PHP are not currently available.
22
+
For in-app frames, the PHP SDK reads source files directly at runtime and includes surrounding lines of code when those files are readable by the process. PHP does not use symbol set uploads for this.
23
23
24
24
</CalloutBox>
25
25
@@ -36,7 +36,7 @@ PostHog\PostHog::init(
36
36
);
37
37
```
38
38
39
-
You can find your project token and instance address in the [project settings](https://us.posthog.com/settings/project) page in PostHog.
39
+
You can find your project token and instance address in the [project settings](https://app.posthog.com/settings/project) page in PostHog.
40
40
41
41
</Step>
42
42
@@ -50,7 +50,7 @@ Use `captureException` to manually capture exceptions and send them to PostHog a
Automatic capture is opt-in for PHP. When enabled, the SDK installs handlers for uncaught exceptions. With the default `capture_errors: true`, it also captures PHP errors and fatal shutdown errors.
80
+
81
+
```php
82
+
PostHog\PostHog::init(
83
+
'<ph_project_token>',
84
+
[
85
+
'host' => '<ph_client_api_host>',
86
+
'error_tracking' => [
87
+
'enabled' => true,
88
+
],
89
+
]
90
+
);
91
+
```
92
+
93
+
<CalloutBoxicon="IconInfo"title="Existing handlers are preserved"type="fyi">
94
+
95
+
The SDK chains existing exception and error handlers instead of replacing your app's behavior.
96
+
97
+
</CalloutBox>
98
+
99
+
</Step>
100
+
101
+
<Steptitle="Identify users and attach request context (recommended)"badge="recommended">
102
+
103
+
By default, automatically captured errors are anonymous. Use `context_provider` to attach a `distinctId` and request metadata to every automatically captured error event.
104
+
105
+
```php
106
+
PostHog\PostHog::init(
107
+
'<ph_project_token>',
108
+
[
109
+
'host' => '<ph_client_api_host>',
110
+
'error_tracking' => [
111
+
'enabled' => true,
112
+
'context_provider' => static function (array $payload): array {
Trigger a test exception to confirm events are being sent to PostHog. You should see them appear in the [Error Tracking](https://us.posthog.com/error_tracking) tab.
168
+
Trigger a test exception to confirm events are being sent to PostHog. You should see them appear in the [Error Tracking](https://app.posthog.com/error_tracking) tab.
Copy file name to clipboardExpand all lines: contents/docs/libraries/php/index.mdx
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ features:
10
10
userIdentification: true
11
11
featureFlags: true
12
12
groupAnalytics: true
13
+
errorTracking: true
13
14
surveys: false
14
15
llmAnalytics: false
15
16
---
@@ -142,6 +143,28 @@ PostHog::groupIdentify([
142
143
143
144
The `name` is a special property which is used in the PostHog UI for the name of the group. If you don't specify a `name` property, the group ID will be used instead.
144
145
146
+
## Error tracking
147
+
148
+
The PHP SDK supports both manual exception capture and opt-in automatic error tracking.
149
+
150
+
To automatically capture uncaught exceptions, PHP errors, and fatal shutdown errors, enable `error_tracking` when initializing the client:
151
+
152
+
```php
153
+
PostHog::init(
154
+
'<ph_project_token>',
155
+
[
156
+
'host' => '<ph_client_api_host>',
157
+
'error_tracking' => [
158
+
'enabled' => true,
159
+
],
160
+
],
161
+
);
162
+
```
163
+
164
+
You can also call `PostHog::captureException()` directly for manual capture. When source files are readable at runtime, PostHog includes surrounding source lines for in-app stack frames automatically.
165
+
166
+
For the full setup guide, including `context_provider`, excluded exceptions, and verification steps, see the [PHP error tracking installation docs](/docs/error-tracking/installation/php).
167
+
145
168
## Config options
146
169
147
170
When calling `PostHog::init`, there are various configuration options you can set apart from the host. Pass them into your client initialisation like so:
@@ -170,6 +193,7 @@ All possible options below:
170
193
|`maximum_backoff_duration`<br/><br/>**Type:** Integer<br/>**Default:**`10000`| Request retry backoff. Retries will stop after this duration is hit |
171
194
|`consumer`<br/><br/>**Type:** String<br/>**Default:**`lib_curl`| One of `socket`, `file`, `lib_curl`, and `fork_curl`. Determines what transport option to use for analytics capture. [More details here](https://github.com/PostHog/posthog-php/blob/master/lib/Consumer/File.php)|
172
195
|`debug`<br/><br/>**Type:** Boolean<br/>**Default:**`false`| Output debug logs or not |
196
+
|`error_tracking`<br/><br/>**Type:** Array<br/>**Default:**`[]`| Enables automatic error tracking and related options such as `context_provider`, `excluded_exceptions`, and `max_frames`. [See the setup guide](/docs/error-tracking/installation/php). |
0 commit comments