|
| 1 | +--- |
| 2 | +title: Starting the Debugger |
| 3 | +--- |
| 4 | + |
| 5 | +Once PHP Debugger is installed and loaded, it is ready. Debugging is on, every |
| 6 | +request starts a session, and the debugger connects whenever your editor is |
| 7 | +listening. **We recommend leaving it exactly like that.** Used the way it is meant |
| 8 | +to be used, the cost of having it there is very small. |
| 9 | + |
| 10 | +Everything below is for the cases where you need something different. You probably |
| 11 | +do not. |
| 12 | + |
| 13 | +## Turning it off entirely |
| 14 | + |
| 15 | +`php_debugger.mode` decides whether the debugger does anything at all. It takes two |
| 16 | +values: |
| 17 | + |
| 18 | +| Value | Meaning | |
| 19 | +| --- | --- | |
| 20 | +| `debug` | Step debugging is available. This is the default. | |
| 21 | +| `off` | The debugger does nothing. | |
| 22 | + |
| 23 | +Anything else is rejected. Modes for profiling, coverage, tracing, |
| 24 | +garbage-collection statistics and development helpers are not supported, because |
| 25 | +those features are not part of this project. Setting one logs an error and falls |
| 26 | +back to the default. |
| 27 | + |
| 28 | +Reach for `off` only if you want *no* overhead rather than *very small* overhead — |
| 29 | +a benchmark you want undisturbed, or a long-running migration you would rather not |
| 30 | +share the machine with. For everyday development the difference is not worth the |
| 31 | +switch. |
| 32 | + |
| 33 | +## Not starting with every request |
| 34 | + |
| 35 | +`php_debugger.start_with_request` decides when a session begins. It defaults to |
| 36 | +`yes`: every request starts one, and connects if your editor is listening. |
| 37 | + |
| 38 | +| Value | Meaning | |
| 39 | +| --- | --- | |
| 40 | +| `yes` | Start a session with every request. The default. | |
| 41 | +| `no` | Never start a session. | |
| 42 | +| `trigger` | Start only when a trigger is present. | |
| 43 | + |
| 44 | +### `no`, and starting later |
| 45 | + |
| 46 | +With `no`, the debugger never starts on its own — and it cannot be started later |
| 47 | +either. Connecting mid-request with `php_debugger_connect_to_client()` does |
| 48 | +nothing, and neither does `php_debugger_break()`, nor an error or exception. |
| 49 | + |
| 50 | +Setting `php_debugger.on_demand_debugging_enabled=1` makes all three work, letting |
| 51 | +the debugger attach part-way through a request. |
| 52 | + |
| 53 | +:::warning[On-demand debugging is expensive] |
| 54 | + |
| 55 | +It is off by default for a reason. To be able to attach at any moment, every |
| 56 | +request has to be compiled with debugging instrumentation, whether or not it ends |
| 57 | +up being debugged. |
| 58 | + |
| 59 | +The near-zero overhead you would otherwise get drops to roughly half of it. Turn |
| 60 | +it on only if you genuinely need to attach mid-request. |
| 61 | + |
| 62 | +::: |
| 63 | + |
| 64 | +### `trigger` |
| 65 | + |
| 66 | +With `trigger`, a session starts only when a trigger value is present in the |
| 67 | +request. Nothing happens otherwise. |
| 68 | + |
| 69 | +The debugger looks for a trigger under any of these names, in this order: |
| 70 | + |
| 71 | +1. `XDEBUG_TRIGGER` |
| 72 | +2. `PHP_DEBUGGER_TRIGGER` |
| 73 | +3. `XDEBUG_SESSION` |
| 74 | +4. `PHP_DEBUGGER_SESSION` |
| 75 | + |
| 76 | +Each is looked for in the environment first, then `$_GET`, then `$_POST`, then |
| 77 | +`$_COOKIE`. So both of these start a session: |
| 78 | + |
| 79 | +```bash |
| 80 | +PHP_DEBUGGER_TRIGGER=1 php your-script.php |
| 81 | +``` |
| 82 | + |
| 83 | +``` |
| 84 | +https://example.test/page.php?PHP_DEBUGGER_TRIGGER=1 |
| 85 | +``` |
| 86 | + |
| 87 | +By default *any* value will do. `php_debugger.trigger_value` turns that into a |
| 88 | +shared secret — the trigger only counts if its value matches, and a value that |
| 89 | +does not match is refused and logged: |
| 90 | + |
| 91 | +```ini |
| 92 | +php_debugger.start_with_request=trigger |
| 93 | +php_debugger.trigger_value=letmein |
| 94 | +``` |
| 95 | + |
| 96 | +Several secrets can be accepted at once by separating them with commas, which is |
| 97 | +useful when more than one person shares an environment. |
| 98 | + |
| 99 | +Worth saying plainly: `trigger` was how you kept a heavyweight debugger out of the |
| 100 | +way when it was not needed. That is not the problem here — an idle session costs |
| 101 | +almost nothing — so the default of `yes` is usually the better choice. |
| 102 | + |
| 103 | +## Keeping the overhead low |
| 104 | + |
| 105 | +The cost of running the debugger depends on what it is doing: |
| 106 | + |
| 107 | +| Situation | Cost | |
| 108 | +| --- | --- | |
| 109 | +| No client connected | Near zero. | |
| 110 | +| Client connected, nothing set | Low. | |
| 111 | +| Breakpoints set, stepping through code | Real, and unavoidable — this is the work you asked for. | |
| 112 | + |
| 113 | +The middle row is the one that catches people out. A session you forgot about is |
| 114 | +not free, and neither are breakpoints you no longer need. |
| 115 | + |
| 116 | +:::tip[Two habits worth keeping] |
| 117 | + |
| 118 | +- **Remove breakpoints once you are done with them.** Every one left behind is |
| 119 | + checked on every request. |
| 120 | +- **Disconnect your editor when you stop debugging.** With nothing listening, the |
| 121 | + debugger drops back to costing almost nothing. |
| 122 | + |
| 123 | +::: |
0 commit comments