首页 > 开发 > Php > 正文

PHP调试的强悍利器之PHPDBG

2020-02-21 20:43:51
字体:
来源:转载
供稿:网友

PHPDBG是一个PHP的SAPI模块,可以在不用修改代码和不影响性能的情况下控制PHP的运行环境。

PHPDBG的目标是成为一个轻量级、强大、易用的PHP调试平台。可以在PHP5.4和之上版本中使用。在php5.6和之上版本将内部集成。

主要功能:

– 单步调试

– 灵活的下断点方式(类方法、函数、文件:行、内存地址、opcode)

– 可直接调用php的eval

– 可以查看当前执行的代码

– 用户空间API(userland/user space)

– 方便集成

– 支持指定php配置文件

– JIT全局变量

– readline支持(可选),终端操作更方便

– 远程debug,使用java GUI

– 操作简便(具体看help)

安装
为了使用phpdgb,你首先需要下载一个php的源码包。然后下载phpdgb的源码包,并放在php源码包的sapi目录下。最后,你就可以执行命令安装了。编译安装示例如下:

假设我们已经下载php的源码包,并放在了/home/php目录下。

#cd /home/php/sapi#git clone https://github.com/krakjoe/phpdbg#cd ../#./buildconf --force#./config.nice#make -j8#make install-phpdbg

注意:

1、如果你的php版本是php5.6或者更高的版本,phpdbg已经集成在php的代码包中,无需单独下载了。

2、编译参数中记得要加 –enable-phpdbg。

3、编译时参数,–with-readline 可以选择性添加。如果不添加,phpdbg的history等功能无法使用。

基本使用
1、参数介绍
phpdbg是php的一个sapi,它可以以命令行的方式调试php。常用参数如下:

The following switches are implemented (just like cli SAPI):

-n ignore php ini

-c search for php ini in path

-z load zend extension

-d define php ini entry

The following switches change the default behaviour of phpdbg:

-v disables quietness

-s enabled stepping

-e sets execution context

-b boring – disables use of colour on the console

-I ignore .phpdbginit (default init file)

-i override .phpgdbinit location (implies -I)

-O set oplog output file

-q do not print banner on startup

-r jump straight to run

-E enable step through eval()

Note: passing -rr will cause phpdbg to quit after execution, rather than returning to the console

2、常用功能
之前我们介绍过gdb工具。其实phpdbg和gdb功能有些地方非常相似。如,可以设置断点,可以单步执行,等。只是他们调试的语言不一样,gdb侧重于调试c或者c++语言,而phpdbg侧重于调试php语言。下面我们将对phpdbg的一些常用调试功能做下介绍。要调试的代码如下:

文件test_phpdbg_inc.php源代码如下:

<?php function phpdbg_inc_func(){     echo "phpdbg_inc_func /n"; } ?>            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表