phpstorm 调试_PhpStorm中的多用户调试

phpstorm 调试

by Ray Naldo

雷·纳尔多(Ray Naldo)

PhpStorm中的多用户调试 (Multi-User Debugging in PhpStorm)

使用Xdebug和DBGp代理 (Using Xdebug and DBGp Proxy)

“Er, wait a minute… Don’t you just use xdebug.remote_connect_back which has been introduced since Xdebug 2.1?"

“嗯,请稍等...您不只是使用Xdebug 2.1之后引入的xdebug.remote_connect_back吗?”

Sure if the web server is only accessible by the developers (e.g. private development server), and if it’s not running behind a NATted firewall, and if you want this guide to end here. See those IFs? Personally, I don’t like IF in programming or in life. So this guide will take the longer way which doesn’t need an IF to start (or at least fewer IFs), that is by using Xdebug’s DBGp proxy.

确保Web服务器仅可由开发人员访问(例如,私有开发服务器),并且它不在NATted防火墙后面运行,以及是否希望本指南在此处结束。 看到那些IF吗? 就个人而言,我在编程或生活中都不喜欢IF。 因此,本指南将采用更长的方式,即不需要使用IF(或者至少需要更少的IF)来启动,即使用Xdebug的DBGp代理。

When a proxy is used, the PHP Xdebug extension no longer connects to PhpStorm directly, but instead connects to the DBGp proxy server. All developers in the team, in turn, then connect to that proxy. Each developer has a separate debugging session running over this proxy, which makes it possible to do multi-user debugging of the same code on the same server.

使用代理时,PHP Xdebug扩展不再直接连接到PhpStorm,而是连接到DBGp代理服务器。 然后,团队中的所有开发人员都将连接到该代理。 每个开发人员都在此代理上运行单独的调试会话,这使得可以对同一服务器上的相同代码进行多用户调试。

So, with DBGp proxy you can limit who can connect to the proxy, and you may have multiple developers debugging the same web server running behind a NATted firewall.

因此,使用DBGp代理,您可以限制谁可以连接到代理,并且可能有多个开发人员调试在NATted防火墙后运行的同一Web服务器。

Running a DBGp proxy also allows you to avoid NAT issues where (as seen from PHP+Xdebug on the server) all connections seem to come from the same IP (because your internal network is NATted). In this case, you can simply run the dbgp proxy on your NAT machine, configure xdebug.remote_host setting to the IP address of your NAT machine, and configure the IDEs to connect to the proxy running at <NAT-machine>;:9001.

运行DBGp代理还可以避免NAT问题(如从服务器上PHP + Xdebug看到的),所有连接似乎都来自同一IP(因为您的内部网络已被NAT)。 在这种情况下,您只需在NAT计算机上运行dbgp代理,将xdebug.remote_host设置配置为NAT计算机的IP地址,然后将IDE配置为连接到运行在<NAT-machine>上的代理; :9001。

https://derickrethans.nl/debugging-with-multiple-users.html

https://derickrethans.nl/debugging-with-multiple-users.html

建立 (Setup)

Mappings between the project folders and the folders on the server should be done correctly in PhpStorm first for debugging to work.

应该首先在PhpStorm中正确完成项目文件夹和服务器上的文件夹之间的映射,然后才能进行调试。

设置Web服务器 (Setup Web Server)

Although this guide assumes the web server is running on Linux, the guide could also be used on non-Linux web servers with slight modifications.

尽管本指南假定Web服务器在Linux上运行,但该指南也可以在非Linux Web服务器上使用,并稍加修改。

1. Install Xdebug.

1.安装Xdebug。

# PHP 7+pecl install xdebug  # PHP 5.6.xpecl install xdebug-2.5.5

2. Enable Xdebug extension, then add the following Xdebug configuration to php.ini:

2.启用Xdebug扩展,然后将以下Xdebug配置添加到php.ini:

[xdebug]zend_extension="<full_path_to_xdebug.so>"
; debugger settingsxdebug.remote_enable=1xdebug.remote_host=127.0.0.1xdebug.remote_port=9000

For this guide, DBGp proxy will run on the same machine as the web server and will use Xdebug’s default port, hence 127.0.0.1:9000.

对于本指南,DBGp代理将与Web服务器在同一台计算机上运行,​​并将使用Xdebug的默认端口,即127.0.0.1:9000

3. Download and install DBGp proxy for remote debugging from Komodo Remote Debugging Package, specifically for your web server’s operating system. This guide will be using 64-bit Linux and PHP Remote Debugging client v11.1.0. Extract the archive; for simplicity I extract all the contents to my home directory i.e. /home/ray/.

3.从Komodo Remote Debugging Package中下载并安装DBGp代理,以进行远程调试,特别是针对Web服务器的操作系统。 本指南将使用64位Linux和PHP远程调试客户端v11.1.0。 提取档案; 为简单起见,我将所有内容提取到我的主目录(即/home/ray/

4. Run DBGp proxy by executing pydbgpproxy file with parameters:

4.通过执行带有参数的pydbgpproxy文件来运行DBGp代理:

  • -d <ip_address:port> to set IP address and port of the machine which will be receiving debugger connection from the web server

    -d <ip_address:po rt>设置将要从Web服务器接收调试器连接的计算机的IP地址和端口

  • -i <ip_address:port> to set IP address and port of the machine which will be receiving debugging connection from developer computer

    -i <ip_address:po rt>设置将要从开发人员计算机接收调试连接的计算机的IP地址和端口

In this guide, web server and DBGp proxy will be run on the same machine. If the IP address is 10.211.1.32 and we want to run the proxy on port 9001 then the command will be:

在本指南中,Web服务器和DBGp代理将在同一台计算机上运行。 如果IP地址为10.211.1.32并且我们想在端口9001上运行代理,则命令将为:

pydbgpproxy -d 127.0.0.1:9000 -i 10.211.1.32:9001

For convenience we could use this script, saved as start-dbgp-proxy.sh.I placed it on the same directory as pydbgpproxy i.e. /home/ray/start-dbgp-proxy.sh) :

为方便起见,我们可以使用这个脚本,保存为start-dbgp-proxy.sh 。我把它放在同一个目录中pydbgpproxy/home/ray/start-dbgp-proxy.sh ):

ip=$(hostname -I | awk '{$1=$1};1')pydbgpproxy -d 127.0.0.1:9000 -i $ip:9001

5. Make sure to allow connection from localhost on port 9000, and from developer machines on port 9001.

5.确保允许从端口9000上的localhost和端口9001上的开发人员机器进行连接。

6. Run start-dbgp-proxy.sh. Add execute file permission if you can't run it.

6.运行start-dbgp-proxy.sh 。 添加执行文件权限(如果无法运行)。

start-dbgp-proxy.sh

Make sure it can be run without a problem.

确保它可以正常运行。

INFO: dbgp.proxy: starting proxy listeners.  appid: 30430INFO: dbgp.proxy:     dbgp listener on 127.0.0.1:9000INFO: dbgp.proxy:     IDE listener on  10.211.1.32:9001

7. (Optional) Auto-start start-dbgp-proxy.sh on each machine startup by using crontab.

7.(可选)使用crontab在每次启动计算机时自动启动start-dbgp-proxy.sh

Edit crontab:

编辑crontab:

crontab -e

Add cron job to auto-start start-dbgp-proxy.sh on each startup:

在每次启动时将cron作业添加到自动启动start-dbgp-proxy.sh

@reboot /home/ray/start-dbgp-proxy.sh

设置客户端 (Setup Client)

1. Access menu Tools > DBGp Proxy > Register IDE on PhpStorm.

1.在PhpStorm上访问菜单Tools > DBGp Proxy > Regist IDE。

2. Fill IDE key with unique string between developers. FillHost andPort with DBGp proxy's IP address and port (parameter -i on Setup Server #4).

2.用开发人员之间的唯一字符串填充IDE key 。 用DBGp代理的IP地址和端口(在Setup Server#4上的参数-i )填充HostPort

3. Click OK. You should see a success notification popup. If you don’t see it, re-register IDE via Tools > DBGp Proxy > Register IDE. If it's failed or you want to change the configuration, do it via Tools > DBGp Proxy > Configuration...

3.单击确定。 您应该看到一个成功通知弹出窗口。 如果看不到,请通过Tools > DBGp Proxy > Regist IDE重新注册IDE。 如果失败或要更改配置,请不要t via Tools > DBGp Proxy > Conf配置” ...

4. (Optional) If you want to initiate debugging connection from the web browser, it’s recommended to install a debugging extension on your browser: Xdebug Helper Firefox or Xdebug Helper Chrome. Then configure your Xdebug Helper.

4.(可选)如果要通过Web浏览器启动调试连接,建议在浏览器上安装调试扩展程序: Xdebug Helper FirefoxXdebug Helper Chrome 。 然后配置您的Xdebug助手。

On Firefox, right click Xdebug Helper icon > Manage Extension… > Options On Chrome, right click Xdebug Helper icon > Options

在Firefox上,右键单击Xdebug Helper图标>管理扩展…>选项在Chrome上,右键单击Xdebug Helper图标>选项

Fill and save IDE key with the same unique string as when you're registering the IDE (Step #2).

使用与注册IDE时相同的唯一字符串填充并保存IDE key ( 第2步 )。

开始调试 (Start Debugging)

1. Set breakpoint(s) on PhpStorm.

1.在PhpStorm上设置断点。

2. Start listening to debug connection in PhpStorm by clicking the ‘phone’ button on the upper right toolbar or from menu Run > Start Listening for PHP Debug Connections. This will enable PhpStorm to react and opens the Debug window automatically when a debugging session is started.

2.单击右上方工具栏上的“电话”按钮,或从菜单中的Run > Start Listening for PHP Debug Connecti PhpStorm中的Run > Start Listening for PHP Debug Connecti 。 启动调试会话时,这将使PhpStorm作出React并自动打开“调试”窗口。

3. Activate Xdebug’s debugger when doing a request. According to Xdebug Documentation there’re 3 ways to do this. But IMHO, the best way which works for all kinds of HTTP methods is by setting a cookie named XDEBUG_SESSION with value <IDE_key> which is the same unique string when we register our IDE to DBGp proxy (Setup Client #2).

3.在执行请求时激活Xdebug的调试器。 根据Xdebug文档,有3种方法可以做到这一点。 但是恕我直言,适用于所有HTTP方法的最佳方法是设置一个名为XDEBUG_SESSION的cookie,其值为<IDE_k ey>,当我们将IDE注册到DBGp poxy (安装程序 #2)时,该cookie是相同的唯一字符串。

  • In the web browser, the cookie will be set automatically by Xdebug Helper extension

    在Web浏览器中,将通过Xdebug Helper扩展自动设置cookie。
  • In Postman, the cookie can be set in Request Headers

    在邮递员中,可以在“请求标题”中设置Cookie

4. Run the script with the cookie already set.

4.在已设置cookie的情况下运行脚本。

5. On success, PhpStorm will show the Debug window automatically.

5.成功后,PhpStorm将自动显示“调试”窗口。

6. Make sure to unset/don’t send the cookie to disable debug and stop listening debug connection in PhpStorm if you’re not doing any debugging. If you fail to do so, it will make the DBGp proxy hang when there’s too many hanging connections.

6.如果您不进行任何调试,请确保取消设置/不发送cookie来禁用调试并停止监听PhpStorm中的调试连接。 如果您这样做失败,则当挂起的连接过多时,它将使DBGp代理挂起。

Hope this guide works for you.

希望本指南对您有用。

Thank you for reading!

感谢您的阅读!

参考文献 (References)

翻译自: https://www.freecodecamp.org/news/multi-user-debugging-in-phpstorm-75ef628ed50f/

phpstorm 调试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值