欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-04-29 20:00:30
...
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.tgzlinux-06bq:/data/software/ # tar zxvf xdebug-2.2.1.tgzlinux-06bq:/data/software/ # cd xdebug-2.2.1/ # 编译安装xdebuglinux-06bq:/data/software/xdebug-2.2.1/ # phpizelinux-06bq:/data/software/xdebug-2.2.1/ # ./configure --with-php-config=/usr/local/services/php/bin/php-config --enable-xdebuglinux-06bq:/data/software/xdebug-2.2.1/ # makelinux-06bq:/data/software/xdebug-2.2.1/ # sudo make installInstalling 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 touse zend_extension_debug=. From PHP 5.3 onwards, you always need to use thezend_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 matchwith 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 xdebugxdebuglinux-06bq:/data/software/xdebug-2.2.1/ # php -r "phpinfo();" |grep xdebugxdebugxdebug support => enabledxdebug.auto_trace => Off => Offxdebug.cli_color => 0 => 0xdebug.collect_assignments => Off => Offxdebug.collect_includes => On => Onxdebug.collect_params => 0 => 0xdebug.collect_return => Off => Offxdebug.collect_vars => Off => Offxdebug.coverage_enable => On => Onxdebug.default_enable => On => Onxdebug.dump.COOKIE => no value => no valuexdebug.dump.ENV => no value => no valuexdebug.dump.FILES => no value => no valuexdebug.dump.GET => no value => no valuexdebug.dump.POST => no value => no valuexdebug.dump.REQUEST => no value => no valuexdebug.dump.SERVER => no value => no valuexdebug.dump.SESSION => no value => no valuexdebug.dump_globals => On => Onxdebug.dump_once => On => Onxdebug.dump_undefined => Off => Offxdebug.extended_info => On => Onxdebug.file_link_format => no value => no valuexdebug.idekey => no value => no valuexdebug.max_nesting_level => 100 => 100xdebug.overload_var_dump => On => Onxdebug.profiler_aggregate => Off => Offxdebug.profiler_append => Off => Offxdebug.profiler_enable => Off => Offxdebug.profiler_enable_trigger => Off => Offxdebug.profiler_output_dir => /tmp => /tmpxdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%pxdebug.remote_autostart => Off => Offxdebug.remote_connect_back => Off => Offxdebug.remote_cookie_expire_time => 3600 => 3600xdebug.remote_enable => Off => Offxdebug.remote_handler => dbgp => dbgpxdebug.remote_host => localhost => localhostxdebug.remote_log => no value => no valuexdebug.remote_mode => req => reqxdebug.remote_port => 9000 => 9000xdebug.scream => Off => Offxdebug.show_exception_trace => Off => Offxdebug.show_local_vars => Off => Offxdebug.show_mem_delta => Off => Offxdebug.trace_enable_trigger => Off => Offxdebug.trace_format => 0 => 0xdebug.trace_options => 0 => 0xdebug.trace_output_dir => /tmp => /tmpxdebug.trace_output_name => trace.%c => trace.%cxdebug.var_display_max_children => 128 => 128xdebug.var_display_max_data => 512 => 512xdebug.var_display_max_depth => 3 => 3OLDPWD => /data/software/xdebug-2.2.1_SERVER["OLDPWD"] => /data/software/xdebug-2.2.1 # 最后重启服务器或php-fpm即可(根据当前服务器加载PHP模式而定)

3.测试用例

简单的测试用例如下:

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】

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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • PHP调试凶器Xdebug安装配置教程
  • 专题推荐

    作者信息
    PHP调试凶器Xdebug安装配置教程

    认证0级讲师

    推荐视频教程
  • PHP调试凶器Xdebug安装配置教程javascript初级视频教程
  • PHP调试凶器Xdebug安装配置教程jquery 基础视频教程
  • 视频教程分类