|
2 | 2 | title: Environment Variables |
3 | 3 | --- |
4 | 4 |
|
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 | +``` |
6 | 113 |
|
7 | | -:::note |
8 | | -This page is a work in progress — full documentation is coming soon. |
9 | 114 | ::: |
| 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. |
0 commit comments