当前位置: 代码迷 >> PHP >> PHP调试凶器Xdebug安装配置教程
  详细解决方案

PHP调试凶器Xdebug安装配置教程

热度:712   发布时间:2013-03-12 11:19:35.0
PHP调试利器Xdebug安装配置教程
  作者:zhanhailiang 日期:2013-03-11

1.简述

引用官方描述:

The Xdebug extension helps you debugging your script by providing a lot of valuable debug information.

2.安装配置教程

# 下载xdebug安装包
linux-06bq:/data/software/ # wget http://xdebug.org/files/xdebug-2.2.1.tgz
linux-06bq:/data/software/ # tar zxvf xdebug-2.2.1.tgz
linux-06bq:/data/software/ # cd xdebug-2.2.1/
 
# 编译安装xdebug
linux-06bq:/data/software/xdebug-2.2.1/ # phpize
linux-06bq:/data/software/xdebug-2.2.1/ # ./configure --with-php-config=/usr/local/services/php/bin/php-config --enable-xdebug
linux-06bq:/data/software/xdebug-2.2.1/ # make
linux-06bq:/data/software/xdebug-2.2.1/ # sudo make install
Installing shared extensions:     /usr/local/services/php/lib/php/extensions/no-debug-non-zts-20090626/
 
  +----------------------------------+
  |                                                                      |
  |   INSTALLATION INSTRUCTIONS                                          |
  |   =========================                                          |
  |                                                                      |
  |   See http://xdebug.org/install.php#configure-php for instructions   |
  |   on how to enable Xdebug for PHP.                                   |
  |                                                                      |
  |   Documentation is available online as well:                         |
  |   - A list of all settings:  http://xdebug.org/docs-settings.php     |
  |   - A list of all functions: http://xdebug.org/docs-functions.php    |
  |   - Profiling instructions:  http://xdebug.org/docs-profiling2.php   |
  |   - Remote debugging:        http://xdebug.org/docs-debugger.php     |
  |                                                                      |
  |                                                                      |
  |   NOTE: Please disregard the message                                 |
  |       You should add "extension=xdebug.so" to php.ini                |
  |   that is emitted by the PECL installer. This does not work for      |
  |   Xdebug.                                                            |
  |                                                                      |
  +----------------------------------+
linux-06bq:/data/software/xdebug-2.2.1/ # cp /usr/local/services/php/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so /usr/local/services/php/extensions/
 
# 修改php配置文件
################################################################
add the following line to php.ini: 
    zend_extension="/wherever/you/put/it/xdebug.so" 
    (for non-threaded use of PHP, for example the CLI, CGI or Apache 1.3 module)
or:
    zend_extension_ts="/wherever/you/put/it/xdebug.so" 
    (for threaded usage of PHP, for example the Apache 2 work MPM or the the ISAPI module). 
Note: In case you compiled PHP yourself and used --enable-debug you would have to
use zend_extension_debug=. From PHP 5.3 onwards, you always need to use the
zend_extension PHP.ini setting name, and not zend_extension_ts, nor zend_extension_debug.
However, your compile options (ZTS/normal build; debug/non-debug) still need to match
with what PHP is using.
################################################################
linux-06bq:/data/software/xdebug-2.2.1/ # vim /usr/local/services/php/etc/php.ini
 
# zend_extension=/usr/local/services/php/extensions/xdebug.so
 
# 检测xdebug是否加载成功(两种方法,php -m或输出phpinfo()结果)
linux-06bq:/data/software/xdebug-2.2.1/ # php -m|grep xdebug
xdebug
linux-06bq:/data/software/xdebug-2.2.1/ # php -r "phpinfo();" |grep xdebug
xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.idekey => no value => no value
xdebug.max_nesting_level => 100 => 100
xdebug.overload_var_dump => On => On
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_autostart => Off => Off
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => Off => Off
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.scream => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3
OLDPWD => /data/software/xdebug-2.2.1
_SERVER["OLDPWD"] => /data/software/xdebug-2.2.1
 
# 最后重启服务器或php-fpm即可(根据当前服务器加载PHP模式而定)

3.测试用例

简单的测试用例如下:

<?php
header( 'X-Test: Testing' );
setcookie( "TestCookie", "test-value" );
var_dump( xdebug_get_headers() );

输出如下:

array(2) {
  [0] =>
  string(15) "X-Test: Testing"
  [1] =>
  string(33) "Set-Cookie: TestCookie=test-value"
}

高级测试用例――查看变量的zval值

$a = array(1, 2, 3);
$b =& $a;
$c =& $a[2];
 
xdebug_debug_zval('a');

输出如下:

a: (refcount=2, is_ref=1)=array(3) {
  [0] =>
(refcount=1, is_ref=0)=  int(1)
  [1] =>
(refcount=1, is_ref=0)=  int(2)
  [2] =>
(refcount=2, is_ref=1)=  int(3)
}

开始Xdebug之旅吧,少年!【Documentation for: Xdebug 2】

  相关解决方案