here is an example <<simple_http.php>>
<?php
xdebug_break();
$http = new swoole_http_server('0.0.0.0', 9502); //parent process can break with both 2.6.0&2.7.0alpha
$conf = [
'pid_file' => DIR . '/server.pid',
'worker_num' => 1,
'max_request' => 10,
'daemonize' => 0,
];
$http->set($conf);
$http->on('request', function ($request, $response) {
xdebug_break(); //child process cannot break with 2.7.0alpha, but 2.6.0 is OK
$response->header('Content-Type', 'text/html; charset=utf-8');
$response->end('<h1>Hello Swoole. #' . rand(1000, 9999) . '</h1>');
});
$http->start();
I do remote debug with phpstorm
-
phpstorm "Run/Debug Configurations",add "PHP Remote Debug",give it an arbitrary name,no other settings in this dialog
-
phpstorm
File | Settings | Languages & Frameworks | PHP | Servers
Name: simple_http(should be the same with serverName in PHP_IDE_CONFIG in step 3)
Host: your server ip
Port: your server port(9502 in this example)
Debugger: xdebug
select "Use path mappings"
and config the path mapping
-
before start(tell phpstorm to use which server configuration)
export PHP_IDE_CONFIG="serverName=simple_http"
-
start cmd
php -dxdebug.remote_enable=1 -dxdebug.remote_mode=jit -dxdebug.remote_port=9000 -dxdebug.remote_host=10.25.161.110 -dxdebug.remote_autostart=1 simple_http.php
it breaks in first xdebug_break()
but when i send
"curl http://127.0.0.1:9502" [^]
xdebug 2.6.0 can break in second xdebug_break()
xdebug 2.7.0alpha cannot break |