# PHP XDebug Usage ## How To Start ### Flow: * Browser Http Request * Docker / VM PHP-FPM * PHP-FPM xdebug plugin * PHP-FPM xdebug plugin -> phpstorm / vscode ### Setting * `/api/test?XDEBUG_SESSION=PHPSTORM` means this request needs to be xdebuged * `/api/test?XDEBUG_SESSION_START=PHPSTORM` * xdebug triggers debuging and adds a response header such as:`Set-Cookie: XDEBUG_SESSION=PHPSTORM; Path=/` * the browse stores the cookie and auto includes it in subsequent requests. * to stop auto debuging, send a request to the same site with `?XDEBUG_SESSION_STOP=1` ### Setup Static Client IP (Docker/VM) ```ini # xdebug 3.x [xdebug] xdebug.mode = develop,debug # can use the docker/vm ip xdebug.client_host = host.docker.internal # IDE debug extension TCP port xdebug.client_port = 9003 xdebug.start_with_request = trigger xdebug.remote_autostart xdebug.idekey = "PHPSTORM" xdebug.remote_log = /tmp/xdebug.log ``` ## Debug ``` # try to connect to phpstorm bash > curl -v telnet://host.docker.internal:9003 ```  Loading... # PHP XDebug Usage ## How To Start ### Flow: * Browser Http Request * Docker / VM PHP-FPM * PHP-FPM xdebug plugin * PHP-FPM xdebug plugin -> phpstorm / vscode ### Setting * `/api/test?XDEBUG_SESSION=PHPSTORM` means this request needs to be xdebuged * `/api/test?XDEBUG_SESSION_START=PHPSTORM` * xdebug triggers debuging and adds a response header such as:`Set-Cookie: XDEBUG_SESSION=PHPSTORM; Path=/` * the browse stores the cookie and auto includes it in subsequent requests. * to stop auto debuging, send a request to the same site with `?XDEBUG_SESSION_STOP=1` ### Setup Static Client IP (Docker/VM) ```ini # xdebug 3.x [xdebug] xdebug.mode = develop,debug # can use the docker/vm ip xdebug.client_host = host.docker.internal # IDE debug extension TCP port xdebug.client_port = 9003 xdebug.start_with_request = trigger xdebug.remote_autostart xdebug.idekey = "PHPSTORM" xdebug.remote_log = /tmp/xdebug.log ``` ## Debug ``` # try to connect to phpstorm bash > curl -v telnet://host.docker.internal:9003 ```  © Reprint prohibited Support Appreciate the author AliPayWeChat Like 3 如果觉得我的文章对你有用,请随意赞赏