Skip to content

Commit 2a7ba96

Browse files
authored
Using Xdebug with PHPStorm and various updates (#1923)
* Using Xdebug with PHPStorm and various updates * Update debugging.md * Delete .idea/workspace.xml * ZTS support * linter
1 parent e3a1488 commit 2a7ba96

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

core/performance.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
## Enabling the Built-in HTTP Cache Invalidation System
44

5-
Exposing a hypermedia API has [many advantages](http://blog.theamazingrando.com/in-band-vs-out-of-band.html). One of them
5+
Exposing a hypermedia API has [many advantages](http://blog.theamazingrando.com/in-band-vs-out-of-band.html). One
66
is the ability to know exactly which resources are included in HTTP responses created by the API. We used this specificity
77
to make API Platform apps blazing fast.
88

99
When the cache mechanism [is enabled](configuration.md), API Platform collects identifiers of every resource included in
10-
a given HTTP response (including lists, embedded documents and subresources) and returns them in a special HTTP header
10+
a given HTTP response (including lists, embedded documents, and subresources) and returns them in a special HTTP header
1111
called [Cache-Tags](https://support.cloudflare.com/hc/en-us/articles/206596608-How-to-Purge-Cache-Using-Cache-Tags-Enterprise-only-).
1212

1313
A caching [reverse proxy](https://en.wikipedia.org/wiki/Reverse_proxy) supporting cache tags (e.g. Varnish, Cloudflare,
@@ -16,17 +16,17 @@ This means that after the first request, all subsequent requests will not hit th
1616
from the cache.
1717

1818
When a resource is modified, API Platform takes care of purging all responses containing it in the proxy’s
19-
cache. This ensures that the content served will always be fresh, because the cache is purged in real time. Support for
19+
cache. This ensures that the content served will always be fresh because the cache is purged in real-time. Support for
2020
most specific cases such as the invalidation of collections when a document is added or removed or for relationships and
2121
inverse relations is built-in.
2222

2323
### Integrations
2424

2525
#### Built-in Caddy HTTP cache
2626

27-
The API Platform distribution relies on the [Caddy web server](https://caddyserver.com) which provide an official HTTP cache module called [cache-handler](https://github.com/caddyserver/cache-handler), that is based on [Souin](https://github.com/darkweak/souin).
27+
The API Platform distribution relies on the [Caddy web server](https://caddyserver.com) which provides an official HTTP cache module called [cache-handler](https://github.com/caddyserver/cache-handler), that is based on [Souin](https://github.com/darkweak/souin).
2828

29-
The integration using the cache-handler is quite simple. You juste have to update the `api/Dockerfile` to build your caddy instance with the HTTP cache
29+
The integration using the cache handler is quite simple. You just have to update the `api/Dockerfile` to build your caddy instance with the HTTP cache
3030

3131
```diff
3232
# Versions
@@ -61,7 +61,7 @@ Update your Caddyfile with the following configuration:
6161
}
6262
}
6363
```
64-
This will tell to caddy to use the HTTP cache and activate the tag based invalidation API. You can refer to the [cache-handler documentation](https://github.com/caddyserver/cache-handler) or the [souin website documentation](https://docs.souin.io) to learn how to configure the HTTP cache server.
64+
This will tell to caddy to use the HTTP cache and activate the tag-based invalidation API. You can refer to the [cache-handler documentation](https://github.com/caddyserver/cache-handler) or the [souin website documentation](https://docs.souin.io) to learn how to configure the HTTP cache server.
6565

6666
Setup the HTTP cache invalidation in your API Platform project
6767
```yaml
@@ -96,6 +96,7 @@ api_platform:
9696
```
9797
9898
## Configuration
99+
99100
Support for reverse proxies other than Varnish or Caddy with the HTTP cache module can be added by implementing the `ApiPlatform\HttpCache\PurgerInterface`.
100101
Three purgers are available, the built-in caddy http cache purger (`api_platform.http_cache.purger.souin`), the http tags (`api_platform.http_cache.purger.varnish.ban`), the surrogate key implementation
101102
(`api_platform.http_cache.purger.varnish.xkey`). You can specify the implementation using the `purger` configuration node,
@@ -411,7 +412,7 @@ More details are available on the [pagination documentation](pagination.md#parti
411412

412413
Blackfire.io allows you to monitor the performance of your applications. For more information, visit the [Blackfire.io website](https://blackfire.io/).
413414

414-
To configure Blackfire.io follow these simple steps:
415+
To configure Blackfire.io follow these steps:
415416

416417
1. Add the following to your `compose.override.yaml` file:
417418

@@ -444,12 +445,14 @@ export BLACKFIRE_SERVER_TOKEN=xxxxxxxxxx
444445
3. Install and configure the Blackfire probe in the app container, by adding the following to your `./Dockerfile`:
445446

446447
```dockerfile
447-
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
448-
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
448+
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION.(PHP_ZTS ? '-zts' : '');") \
449+
&& architecture=$(uname -m) \
450+
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/$architecture/$version \
449451
&& mkdir -p /tmp/blackfire \
450-
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
451-
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
452-
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8307\n" > $PHP_INI_DIR/conf.d/blackfire.ini
452+
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
453+
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
454+
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8307\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
455+
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
453456
```
454457

455458
4. Rebuild and restart all your containers

distribution/debugging.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,43 @@
44

55
## Xdebug
66

7-
The default Docker stack is shipped without a Xdebug stage. It's easy
8-
though to add [Xdebug](https://xdebug.org/) to your project, for development
9-
purposes such as debugging tests or remote API requests.
7+
For development purposes such as debugging tests or remote API requests,
8+
[Xdebug](https://xdebug.org/) is shipped by default with the API Platform distribution.
109

11-
## Add a Development Stage to the Dockerfile
10+
To enable it, run:
1211

13-
To avoid deploying API Platform to production with an active Xdebug extension,
14-
it's recommended to add a custom stage to the end of the `api/Dockerfile`.
12+
```console
13+
XDEBUG_MODE=debug docker compose up --wait
14+
```
1515

16-
```Dockerfile
17-
# api/Dockerfile
18-
FROM api_platform_php as api_platform_php_dev
16+
## Using Xdebug with PhpStorm
1917

20-
ARG XDEBUG_VERSION=3.1.3
21-
RUN set -eux; \
22-
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
23-
pecl install xdebug-$XDEBUG_VERSION; \
24-
docker-php-ext-enable xdebug; \
25-
apk del .build-deps
26-
```
18+
First, [create a PHP debug remote server configuration](https://www.jetbrains.com/help/phpstorm/creating-a-php-debug-server-configuration.html):
19+
20+
1. In the `Settings/Preferences` dialog, go to `PHP | Servers`
21+
2. Create a new server:
22+
* Name: `api` (or whatever you want to use for the variable `PHP_IDE_CONFIG`)
23+
* Host: `localhost` (or the one defined using the `SERVER_NAME` environment variable)
24+
* Port: `443`
25+
* Debugger: `Xdebug`
26+
* Check `Use path mappings`
27+
* Map the local `api/` directory to the `/app` absolute path on the server
28+
29+
You can now use the debugger!
30+
31+
1. In PhpStorm, open the `Run` menu and click on `Start Listening for PHP Debug Connections`
32+
2. Add the `XDEBUG_SESSION=PHPSTORM` query parameter to the URL of the page you want to debug or use [other available triggers](https://xdebug.org/docs/step_debug#activate_debugger).
33+
Alternatively, you can use [the Xdebug extension](https://xdebug.org/docs/step_debug#browser-extensions) for your preferred web browser.
34+
35+
3. On the command-line, we might need to tell PhpStorm which [path mapping configuration](https://www.jetbrains.com/help/phpstorm/zero-configuration-debugging-cli.html#configure-path-mappings) should be used, set the value of the PHP_IDE_CONFIG environment variable to `serverName=api`, where `api` is the name of the debug server configured higher.
36+
37+
Example:
2738

28-
## Configure Xdebug with Docker Compose Override
39+
```console
40+
XDEBUG_SESSION=1 PHP_IDE_CONFIG="serverName=api" php bin/console ...
41+
```
2942

30-
XDebug is shipped by default with the API Platform distribution.
31-
To enable it, run: `XDEBUG_MODE=debug docker compose up --wait`
43+
## Using Xdebug With VSCode
3244

3345
If you are using VSCode, use the following `launch.json` to debug.
3446
Note that this configuration includes the path mappings for the Docker image.
@@ -51,8 +63,10 @@ Note that this configuration includes the path mappings for the Docker image.
5163
}
5264
```
5365

54-
Note: On Linux, the `client_host` setting of `host.docker.internal` may not work.
55-
In this case you will need the actual local IP address of your computer.
66+
> [!NOTE]
67+
>
68+
> On Linux, the `client_host` setting of `host.docker.internal` may not work.
69+
> In this case you will need the actual local IP address of your computer.
5670
5771
## Troubleshooting
5872

@@ -64,6 +78,6 @@ $ docker compose exec php \
6478
php --version
6579

6680
PHP …
67-
with Xdebug v3.1.3, Copyright (c) 2002-2021, by Derick Rethans
81+
with Xdebug v…, Copyright (c) 2002-2021, by Derick Rethans
6882
6983
```

0 commit comments

Comments
 (0)