Skip to content

Commit d61dc74

Browse files
Merge pull request #24 from php-debugger/environment-variables
write the environment variables page and drop cli options
2 parents c0747bf + d66f8ac commit d61dc74

5 files changed

Lines changed: 132 additions & 16 deletions

File tree

docs/reference/cli-options.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/reference/environment-variables.md

Lines changed: 129 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,134 @@
22
title: Environment Variables
33
---
44

5-
Environment variables that trigger and configure debug sessions at runtime, overriding php.ini settings.
5+
Environment variables let you configure the debugger for a single command without
6+
touching `php.ini` — which is what makes them the natural fit for a container, a CI
7+
job, or a one-off run from your shell.
8+
9+
They are listed here in alphabetical order.
10+
11+
## `PHP_DEBUGGER_CONFIG`
12+
13+
Sets configuration values for this run. The value is a space-separated list of
14+
`key=value` pairs, with the keys written without their `php_debugger.` prefix:
15+
16+
```bash
17+
PHP_DEBUGGER_CONFIG="client_host=192.168.1.10 client_port=9004" php your-script.php
18+
```
19+
20+
Only these keys are accepted:
21+
22+
| Key | |
23+
| --- | --- |
24+
| `client_host` | Where to connect |
25+
| `client_port` | Which port |
26+
| `discover_client_host` | Work the address out from the request |
27+
| `cloud_id` | Relay through Xdebug Cloud |
28+
| `idekey` | Session identifier |
29+
| `log` | Where to write the debug log |
30+
| `log_level` | How much to write |
31+
| `on_demand_debugging_enabled` | Allow attaching mid-request |
32+
33+
Anything else in the list is ignored. Each key behaves exactly as the
34+
[setting](./settings.md) of the same name.
35+
36+
## `PHP_DEBUGGER_IGNORE`
37+
38+
Stops the debugger activating for this request, whatever else is configured.
39+
40+
```bash
41+
PHP_DEBUGGER_IGNORE=1 php ./bin/console cache:clear
42+
```
43+
44+
Any value ignores the request except `no` and `0`, which explicitly do not. It is
45+
the quickest way to keep one command out of a debugging session — a build step or a
46+
cache warm-up you would rather not step through.
47+
48+
## `PHP_DEBUGGER_MODE`
49+
50+
Overrides [`php_debugger.mode`](./settings.md#php_debuggermode) for this run, which
51+
is otherwise settable only in `php.ini`.
52+
53+
```bash
54+
PHP_DEBUGGER_MODE=off php benchmark.php
55+
```
56+
57+
This is the one way to turn the debugger off for a single command without editing
58+
configuration. An unrecognised value is reported and the `php.ini` setting is used
59+
instead.
60+
61+
## `PHP_DEBUGGER_SESSION`
62+
63+
An older name for `PHP_DEBUGGER_TRIGGER`, still honoured. It is only consulted when
64+
no trigger variable was found, so prefer the trigger name in anything new.
65+
66+
## `PHP_DEBUGGER_SESSION_START`
67+
68+
Starts a debugging session for this run, taking the value you give it as the
69+
session's identifier:
70+
71+
```bash
72+
PHP_DEBUGGER_SESSION_START=my-session php your-script.php
73+
```
74+
75+
Over HTTP it does one thing more: alongside starting the session it sets a cookie,
76+
so the requests that follow in the same browser keep debugging without the variable
77+
being present each time.
78+
79+
```
80+
https://example.test/page.php?PHP_DEBUGGER_SESSION_START=1
81+
```
82+
83+
That cookie is what distinguishes it from a plain trigger: a trigger applies to the
84+
request carrying it, whereas this persists across the ones that follow.
85+
86+
## `PHP_DEBUGGER_TRIGGER`
87+
88+
Starts a session when
89+
[`php_debugger.start_with_request`](./settings.md#php_debuggerstart_with_request)
90+
is set to `trigger`. With the default of `yes` it is not needed, because every
91+
request already starts one.
92+
93+
```bash
94+
PHP_DEBUGGER_TRIGGER=1 php your-script.php
95+
```
96+
97+
Any value will do unless
98+
[`php_debugger.trigger_value`](./settings.md#php_debuggertrigger_value) is set, in
99+
which case the value has to match one of the configured secrets.
100+
101+
:::info[Triggers are not only environment variables]
102+
103+
`PHP_DEBUGGER_TRIGGER`, `PHP_DEBUGGER_SESSION` and `PHP_DEBUGGER_SESSION_START` are
104+
each looked for in `$_GET`, then `$_POST`, then `$_COOKIE`, and only then in the
105+
environment — so a query parameter of the same name wins over the environment, not
106+
the other way round.
107+
108+
That is what makes them usable from a browser as well as a shell:
109+
110+
```
111+
https://example.test/page.php?PHP_DEBUGGER_TRIGGER=1
112+
```
6113

7-
:::note
8-
This page is a work in progress — full documentation is coming soon.
9114
:::
115+
116+
## Variables without a `PHP_DEBUGGER_` name
117+
118+
Two more are read, both inherited and neither renamed:
119+
120+
| Variable | |
121+
| --- | --- |
122+
| `DBGP_IDEKEY` | Supplies the session identifier when `php_debugger.idekey` is empty |
123+
| `DBGP_COOKIE` | Passed back to the client in the opening protocol message |
124+
125+
Both exist so that a DBGp proxy can identify the session it set up. You are unlikely
126+
to set either by hand.
127+
128+
## The `XDEBUG_` prefix
129+
130+
Every variable above whose name begins `PHP_DEBUGGER_` also works with an `XDEBUG_`
131+
prefix — `XDEBUG_CONFIG`, `XDEBUG_IGNORE`, `XDEBUG_MODE`, `XDEBUG_SESSION`,
132+
`XDEBUG_SESSION_START` and `XDEBUG_TRIGGER`.
133+
134+
The `XDEBUG_` spelling is checked first, so where both are set that one wins. The
135+
`PHP_DEBUGGER_` names are the ones to prefer in anything new.

docs/user-guide/starting-the-debugger.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ The debugger looks for a trigger under any of these names, in this order:
7373
3. `XDEBUG_SESSION`
7474
4. `PHP_DEBUGGER_SESSION`
7575

76-
Each is looked for in the environment first, then `$_GET`, then `$_POST`, then
77-
`$_COOKIE`. So both of these start a session:
76+
Each is looked for in `$_GET`, then `$_POST`, then `$_COOKIE`, and last of all in
77+
the environment. So both of these start a session:
7878

7979
```bash
8080
PHP_DEBUGGER_TRIGGER=1 php your-script.php

docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const config = {
123123
position: 'left',
124124
},
125125
{
126-
to: '/reference/cli-options',
126+
to: '/reference/settings',
127127
label: 'Reference',
128128
position: 'left',
129129
},

sidebars.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const sidebars = {
4949
items: [
5050
'reference/settings',
5151
'reference/functions',
52-
'reference/cli-options',
5352
'reference/environment-variables',
5453
'reference/debug-protocol',
5554
],

0 commit comments

Comments
 (0)