The number of people using Xdebug in PHP-FPM should be quite high, while the number of people using Xdebug in Swoole is quite low, because the Swoole extension explicitly conflicts with the Xdebug extension
The Sdebug README has also been modified to explain how to install Sdebug, but it simply explains how to successfully load the extension. There is no detailed configuration
How to install Sdebug first
To avoid Swoole’s detecting Xdebug warnings, the extension registration is named Sdebug
git clone [email protected]:swoole/sdebug.git -b sdebug_2_9 --depth=1
cd sdebug
phpize
./configure
make clean
make
make install
Copy the code
Step is very simple, is clone source, into the directory and then compile
If your PHP is a universal installation, without changing the default location, etc., you can also run the script directly from the directory:
Sh If your phpize is not the default path, use the absolute path. For php-config, use –with-php-config= plus your absolute path
After compiling successfully, you need to load the extension in php.ini
Zend_extension =xdebug.so The file name generated after the compilation is still xdebug
Check whether the file is successfully loaded
PHP –ri sdebug Don’t go, it’s not finished, some other configuration is needed, otherwise you’ll find it doesn’t work when you go to breakpoints
We also need to add these configuration items to php.ini
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=localhost
xdebug.remote_port=8000
xdebug.idekey="xdebug"
Copy the code
If Sdebug does not work, you will not be able to use it. In fact, your posture is not correct, the configuration item is not added or added incorrectly
If you need to work with PhpStorm, you also need to configure PhpStorm
Preferences | Languages & Frameworks | PHP | Debug
1 is to automatically give the first line a breakpoint when we don’t add a breakpoint
2 is the remote_port whose configuration is modified
Preferences | Languages & Frameworks | PHP | Servers
Adding a service
Then add a Debug here in the upper right corner and select PHP Remote Debug
Server Select the server we just created and fill in the IDE key with xdebug as configured in php.ini
Then we’ll test a wave, see if it works
Let’s start with a simple TCP Server
$Server = new Swoole\Server('127.0.0.1', 9501); $server->on('Connect', function ($server, $fd) {echo "Client: Connect.\n"; }); $server->on('Receive', function ($server, fd, $from_id, $data) {var_dump($data); $server->send($fd, "Server: " . $data); }); $server->on('Close', function ($server, $fd) {echo "Client: Close.\n"; }); $server->start();Copy the code
Click the green bug in the upper right corner to enter the Debug state and start our service. It will be found that the Server object is automatically broken in line 4
And then the next, the next…
After start we Connect using Telnet, send a message, breakpoint goes to Connect, and then we go to the next step, and the terminal will output Connect
Then we go to var_dump and see that $data is 11111\r\n
And then an HTTP Server
$HTTP = new Swoole\ HTTP \Server('0.0.0.0', 9501); $http->on('request', function ($request, $response) { var_dump($request->server); $response->header("Content-Type", "text/html; charset=utf-8"); $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>"); }); $http->start();Copy the code
You need to add an XDEBUG_SESSION_START parameter to the access or you can add it to the Cookie
It can also be debugged at breakpoints
The use of frameworks is the same, as for other things, use them with Docker, etc.
Here is a screenshot of debugging Hyperf
Another tip, selecting the phone icon in the upper right as shown above, will automatically initiate the Debug service when the service is started from the command line.