繁体   English   中英

使用xdebug和netbeans调试php-cli脚本?

[英]Debugging php-cli scripts with xdebug and netbeans?

我已经设法从IDE本身启动php-cli脚本调试会话,但是我需要从shell /命令行启动调试会话。 这些是相当复杂的维护PHP脚本,需要许多输入参数,因此从Netbeans中输入参数有点麻烦。

我之前在Zend Studio中已经做到了: https : //zend18.zendesk.com/hc/en-us/articles/203838096-Debugging-PHP-CLI-Scripts ,但是现在我需要使其与Netbeans一起使用。

提前致谢。

我通过以下方法在Ubuntu / Netbeans上进行此工作:

  • 将xdebug配置行从/etc/php5/apache2/php.ini文件复制到/etc/php5/cli/php.ini中
  • 设置带有调试会话名称的环境变量(您可以从开始调试时netbeans启动页面的URL中的查询字符串中获取该变量),因此命令为: export XDEBUG_CONFIG="idekey=netbeans-xdebug"

然后,这只是在netbeans中启动调试并在命令行执行php myscript.php情况。

注意:如果要使用netbeans进行远程调试,则需要在从命令行运行的文件上使用Debug File,而不是正常的Debug。

xdebug.remote_autostart=On添加到您的php.ini文件中,或将-dxdebug.remote_autostart=On添加为PHP二进制调用的参数( php -d... script.php )。

参见http://xdebug.org/docs/remote

我将全部放在一起,以下是对我有用的。

file:
/etc/php5/cli/php.ini

zend_extension="/usr/lib/php5/20121212/xdebug.so" -> xdebug bin path
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_port=9000 -> same port configured in netbeans debugging tab
xdebug.idekey="netbeans-xdebug" -> same ide configured in netbeans debuggin tab
xdebug.remote_autostart=1

然后,没有任何其他参数

php脚本.php

我有同样的问题,我的解决方案是这样的:

  1. 环境:Windows下的Netbeans 8.2(apache + php)
  2. 假设您已经将PHP和NetBeans配置为使用Xdebug调试代码( http://wiki.netbeans.org/HowToConfigureXDebug#Notes_on_Windows_Configuration
  3. 在netbeans上创建新的配置(“项目属性”>“运行配置”>“新建...”
  4. 在新的配置集中,不要打开Web浏览器(“高级”>“不要打开Web浏览器”)
  5. 激活新创建的配置(在工具栏中下拉)
  6. 设置调试点
  7. 打开调试(CTRL + F5)
  8. 打开终端窗口(“工具”>“在终端中打开”)
  9. 键入终端:$ export XDEBUG_CONFIG =“ idekey = netbeans-xdebug”(值“ netbeans-xdebug”必须与“工具”>“选项”>“调试”>“会话ID”一致)
  10. 输入终端:$ php.exe -f“ C:\\ Apache24 \\ htdocs \\ www.SiteName \\ ScriptName.php”-“ Arg1 = x&Arg2 = y”
  11. 跟随调试…

我有同样的问题,我的解决方案是这样的:

在Netbeans>项目窗口>右键单击php项目>属性>运行配置。 创建一个新配置。

填写正确的值:

  • 以“脚本”运行
  • 设置PHP解释器
  • 在我的情况下,更改索引文件为“ cron / index.php”。

如果您不想为IDE配置xDebug(我讨厌配置),则可以使用Dephpugger项目。

https://github.com/tacnoman/dephpugger

您可以在终端中运行调试器,例如python的ipdb和Ruby的byebug。

确保还设置了DBGP_IDEKEY值,因为通常它不是idekey 例如在Linux上:

export DBGP_IDEKEY="netbeans-xdebug" 
export XDEBUG_CONFIG="netbeans-xdebug=netbeans-xdebug"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM