cloudflare/Cloudflare-WordPress
Publicmirrored fromhttps://github.com/cloudflare/Cloudflare-WordPress
docs/developer-tools.md
100lines · modecode
5 years ago
| 1 | # Developer tooling |
| 2 | |
| 3 | ## [PsySH](https://psysh.org/) |
| 4 | |
| 5 | At some point in debugging you have probably wrote something like this to get a |
| 6 | quick snippet working. |
| 7 | |
| 8 | ```php |
| 9 | <?php |
| 10 | |
| 11 | require_once "vendor/autoload.php" |
| 12 | |
| 13 | use ... |
| 14 | |
| 15 | // do a few lines of actual work here |
| 16 | ``` |
| 17 | |
| 18 | While this works, it's annoying to do over and over again. Instead, we recommend |
| 19 | installing `psysh` and have a fully loaded shell where you can play with |
| 20 | snippets without the overhead of managing these files. Install is as straight |
| 21 | forward as `composer g require psy/psysh:@stable`. There is also a bunch of |
| 22 | other cool features to take advantage of; check out the website for more details! |
| 23 | |
| 24 | This isn't included in the development dependencies due to too many conflicts |
| 25 | with other packages. |
| 26 | |
| 27 | ## Docker |
| 28 | |
| 29 | To make the development environment somewhat reproducible, we ship a Docker |
| 30 | Compose configuration file in the root of the repository. A simple |
| 31 | `docker compose up -d` at the root of the repository will stand up MySQL, |
| 32 | WordPress running on Apache, MITMProxy and Adminer containers. |
| 33 | |
| 34 | Port mapping is as follows: |
| 35 | |
| 36 | - MySQL: `3306` |
| 37 | - Adminer UI: `9010` |
| 38 | - WordPress: `9999` |
| 39 | - MITMProxy: |
| 40 | - Web UI: `9080` (only accessible from 127.0.0.1, not a domain) |
| 41 | - Listener: `9081` |
| 42 | - XDebug: |
| 43 | - Incoming client connections from `9003` |
| 44 | |
| 45 | ## XDebug |
| 46 | |
| 47 | XDebug is a profiler and debugger for PHP. The container has it built in by |
| 48 | default and all you need to do is have a listener setup on your host machine |
| 49 | matching the ports above and it will be available. We use XDebug 3. |
| 50 | |
| 51 | Example Visual Studio code launch configuration |
| 52 | |
| 53 | ```json |
| 54 | { |
| 55 | "version": "0.2.0", |
| 56 | "configurations": [ |
| 57 | { |
| 58 | "name": "xdebug", |
| 59 | "type": "php", |
| 60 | "request": "launch", |
| 61 | "port": 9003, |
| 62 | "hostname": "localhost", |
| 63 | "pathMappings": { |
| 64 | "/var/www/html/wp-content/plugins/cloudflare": "${workspaceFolder}", |
| 65 | }, |
| 66 | "xdebugSettings": { |
| 67 | "max_data": 65535, |
| 68 | "show_hidden": 1, |
| 69 | "max_children": 100, |
| 70 | "max_depth": 5 |
| 71 | } |
| 72 | } |
| 73 | ] |
| 74 | } |
| 75 | ``` |
| 76 | |
| 77 | If you would like more advanced features such as gcstats, profiling or tracing, |
| 78 | you can toggle them on within the Dockerfile.wordpress by uncommenting the `sed` |
| 79 | replacement and include your modes to enable. |
| 80 | |
| 81 | Outputs are generated to the `xdebug` directory in this repository. |
| 82 | |
| 83 | ## MITM Proxy |
| 84 | |
| 85 | MITMProxy is a tool that allows you to inspect and intercept HTTP traffic. This |
| 86 | is useful if you are making HTTP requests/responses and you want to watch the |
| 87 | transactions in various forms instead of dumping the various components. |
| 88 | |
| 89 | You can also use this from your host machine as the ports are exposed. |
| 90 | |
| 91 | ``` |
| 92 | curl -x 127.0.0.1:9081 http://example.com |
| 93 | ``` |
| 94 | |
| 95 | The web UI lives at 127.0.0.1:9080. |
| 96 | |
| 97 | To use a MITM proxy with WordPress or Guzzle, you will need to ignore SSL |
| 98 | verification otherwise you will recieve certificate errors. Once you update your |
| 99 | code to ignore certificates, you can uncomment the `HTTP_PROXY`/`HTTPS_PROXY` |
| 100 | environment variables in the Docker Compose file to enable it. |