Skip to content

Commit cdc0f19

Browse files
Merge pull request #11 from php-debugger/starting-the-debugger
replace configuration page with starting the debugger guide
2 parents c5d0b67 + 0333921 commit cdc0f19

6 files changed

Lines changed: 127 additions & 36 deletions

File tree

docs/getting-started/configuration.md

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

docs/getting-started/docker.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@ image that already has the debugger in it.
163163

164164
- [More install options](./install-options/index.md) — PIE, prebuilt binaries,
165165
and building from source
166-
- [Configuration](./configuration.md) — the settings you can change
166+
- [Quick Start](./quick-start.md) — pointing your editor at it

docs/getting-started/installation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ With the debugger installed, point your editor at it and set your first
103103
breakpoint:
104104

105105
- [Quick Start](./quick-start.md)
106-
- [Configuration](./configuration.md)
106+
- [Starting the debugger](../user-guide/starting-the-debugger.md)

docs/getting-started/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ See [IDE Support](../integrations/ide-support.md) for PhpStorm, VS Code and Neov
5353

5454
## Next steps
5555

56+
- [Starting the debugger](../user-guide/starting-the-debugger.md) — if you need something other than the defaults
5657
- [Breakpoints](../user-guide/breakpoints.md) and [step debugging](../user-guide/step-debugging.md)
57-
- [Configuration](./configuration.md) — everything you can change, if you need to
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
:::

sidebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ const sidebars = {
2525
],
2626
},
2727
'getting-started/quick-start',
28-
'getting-started/configuration',
2928
],
3029
},
3130
{
3231
type: 'category',
3332
label: 'User Guide',
3433
collapsed: false,
3534
items: [
35+
'user-guide/starting-the-debugger',
3636
'user-guide/breakpoints',
3737
'user-guide/step-debugging',
3838
'user-guide/inspect-variables',

0 commit comments

Comments
 (0)