cloudflare/Cloudflare-WordPress

Public

mirrored fromhttps://github.com/cloudflare/Cloudflare-WordPress

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v4.5.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/developer-tools.md

100lines · modecode

1# Developer tooling
2
3## [PsySH](https://psysh.org/)
4
5At some point in debugging you have probably wrote something like this to get a
6quick snippet working.
7
8```php
9<?php
10
11require_once "vendor/autoload.php"
12
13use ...
14
15// do a few lines of actual work here
16```
17
18While this works, it's annoying to do over and over again. Instead, we recommend
19installing `psysh` and have a fully loaded shell where you can play with
20snippets without the overhead of managing these files. Install is as straight
21forward as `composer g require psy/psysh:@stable`. There is also a bunch of
22other cool features to take advantage of; check out the website for more details!
23
24This isn't included in the development dependencies due to too many conflicts
25with other packages.
26
27## Docker
28
29To make the development environment somewhat reproducible, we ship a Docker
30Compose 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,
32WordPress running on Apache, MITMProxy and Adminer containers.
33
34Port 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
47XDebug is a profiler and debugger for PHP. The container has it built in by
48default and all you need to do is have a listener setup on your host machine
49matching the ports above and it will be available. We use XDebug 3.
50
51Example 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
77If you would like more advanced features such as gcstats, profiling or tracing,
78you can toggle them on within the Dockerfile.wordpress by uncommenting the `sed`
79replacement and include your modes to enable.
80
81Outputs are generated to the `xdebug` directory in this repository.
82
83## MITM Proxy
84
85MITMProxy is a tool that allows you to inspect and intercept HTTP traffic. This
86is useful if you are making HTTP requests/responses and you want to watch the
87transactions in various forms instead of dumping the various components.
88
89You can also use this from your host machine as the ports are exposed.
90
91```
92curl -x 127.0.0.1:9081 http://example.com
93```
94
95The web UI lives at 127.0.0.1:9080.
96
97To use a MITM proxy with WordPress or Guzzle, you will need to ignore SSL
98verification otherwise you will recieve certificate errors. Once you update your
99code to ignore certificates, you can uncomment the `HTTP_PROXY`/`HTTPS_PROXY`
100environment variables in the Docker Compose file to enable it.