我已经能够让我的PHP脚本在从浏览器打开页面时触发PhpStorm的监听器。我只需要在docker中安装Xdebug,并在配置时使用
xdebug.remote_connect_back = On
xdebug.remote_enable = On
xdebug.remote_autostart = Off
现在我希望在docker内调用PHP CLI脚本时触发它。我尝试了几个选项,比如 php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 -dxdebug.remote_connect_back=1 -dxdebug.idekey=PHPSTORM -dxdebug.remote_port=9000 myscript.php
但没有成功。我是不是错过了什么?
所以,感谢@LazyOne的评论,我得到了答案。在docker里面,脚本不知道调试会话应该发送到哪个主机。我只需要从docker的PVP中找到我的电脑IP,并把它作为主机。
找到了 ip addr
并寻找 docker0
项,然后将其作为主机。
export PHP_IDE_CONFIG="serverName=localhost"
php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 -dxdebug.remote_connect_back=1 -dxdebug.idekey=PHPSTORM -dxdebug.remote_port=9000 -dxdebug.remote_host=172.17.0.4 myscript.php
The Dockerfile
需要有 EXPOSE 9000
(打开端口) :9000
)
...... 否则你将无法连接 xdebug
从外部世界。
将IDE放入容器中是值得商榷的。