Home php教程 php手册 PHP调试工具Xdebug安装配置教程

PHP调试工具Xdebug安装配置教程

Jun 21, 2016 am 08:53 AM
php trace xdebug

  说道PHP代码调试,对于有经验的PHPer,通过echo、print_r、var_dump函数,或PHP开发工具zend studio、editplus可解决大部分问题,但是对于PHP入门学习的童鞋来说有一定的难度,而且仅仅通过上述这些PHP调试手段,也很难准确发现PHP性能方面的问题,Xdebug是一个非常有用的PHP调试工具。

  Xdebug作为PHP调试工具,提供了丰富的调试函数,也可将Xdebug安装配置为zend studio、editplus调试PHP的第三方插件,通过开启自动跟踪(auto_trace)和分析器功能,可以直观的看到PHP源代码的性能数据,以便优化PHP代码。今天和大家分享PHP调试工具Xdebug安装以及配置方面的基础知识。

  Xdebug在PHP中的安装配置涉及php.ini配置文件的修改。

  Xdebug安装教程

  下载Xdebug

  首先我们需要下载Xdebug,务必根据安装的PHP版本,选择合适的Xdebug版本,由于我是在Windows环境下安装PHP的(请参考Windows 7下安装配置PHP+Apache+Mysql环境教程),所以选择下载Windows版本的Xdebug2.1.0(5.3 VC6 (32 bit)),下载下来的Xdebug文件为php_xdebug-2.1.0-5.3-vc6.dll,这是由于Xdebug是作为PHP模块的形式被安装配置与使用的。

  Xdebug安装提示:如果你不清楚安装的PHP版本,你可以通过phpinfo()函数参看,同时Xdebug也提供了phpinfo输出信息分析工具来帮助你分析如何安装Xdebug,只要将phpinfo输出信息复制提交即可,地址:Xdebug phpinfo信息分析地址

  安装Xdebug

  将下载的php_xdebug-2.1.0-5.3-vc6.dll复制到PHP安装目录下的ext目录,此处为C:\php\ext,ext目录专门用来存放PHP扩展库DLL文件。

  配置php.ini

  安装Xdebug的最后一步就是配置php.ini文件,打开C:\php目录下的php.ini配置文件,在末尾添加

1
2

[Xdebug]
zend_extension="c:/php/ext/php_xdebug-2.1.0-5.3-vc6.dll"

最后重启Apache服务器,通过phpinfo()函数,可以看到

PHP Xdebug配置信息

  Xdebug配置提示:PHP5.3之前版本配置Xdebug时使用zend_extension_ts,对于PHP5.3以上版本,使用zend_extension。

  XDEBUG NOT LOADED AS ZEND EXTENSION信息出现的原因

  出现XDEBUG NOT LOADED AS ZEND EXTENSION的原因是在安装Xdebug时由于我们将Xdebug的DLL文件复制到了php\ext目录下,容易以PHP扩展库的形式加载Xdebug,在php.ini文件中添加了

1

extension=php_xdebug-2.1.0-5.3-vc6.dll

这是错误的Xdebug安装方式,必须以zend方式加载。

  至此PHP Xdebug的基础安装教程就结束了,下面我们需要对Xdebug作一些基础配置。

Xdebug配置教程

  在安装完Xdebug后,我们还需要对Xdebug做基础配置,默认Xdebug的PHP函数自动跟踪(auto_trace)功能、分析器功能并没有开启,作为调试PHP代码的需要,有些Xdebug配置选项最好开启。

  在此之前我们需要创建Xdebug自动跟踪以及分析器输出文件的存放目录,务必确保目录是可读写的,此处我在D:\PHPWeb\下创建了xdebug\trace以及xdebug\profiler目录。

  最后在php.ini配置文件中完成Xdebug的配置工作,找到

1
2

[Xdebug]
zend_extension="c:/php/ext/php_xdebug-2.1.0-5.3-vc6.dll"

在此之后添加Xdebug配置信息

1
2
3
4
5
6

xdebug.auto_trace=1
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.trace_output_dir="D:/PHPWeb/xdebug/trace"
xdebug.profiler_enable=1
xdebug.profiler_output_dir="D:/PHPWeb/xdebug/profiler"

最后保存php.ini,并重启Aapche服务器即可。

Xdebug部分配置选项说明

  xdebug.auto_trace = 1

  是否允许Xdebug跟踪函数调用,跟踪信息以文件形式存储,默认值为0

  collect_params = 1

  是否允许Xdebug跟踪函数参数,默认值为0

  xdebug.collect_return = 1

  是否允许Xdebug跟踪函数返回值,默认值为0

  xdebug.profiler_enable = 1

  打开xdebug的性能分析器,以文件形式存储,这项配置是不能以ini_set()函数配置的,默认值为0

  xdebug.profiler_output_dir

  性能分析文件的存放位置,默认值为/tmp

  xdebug.profiler_output_name

  性能分析文件的命名规则,默认值为cachegrind.out.%p

  xdebug.trace_output_dir

  函数调用跟踪信息输出文件目录,默认值为/tmp

  xdebug.trace_output_name

  函数调用跟踪信息输出文件命名规则,默认为trace.%c

  特别说明:Xdebug的trace和profiler的输出文件名规则是可以更改的,比如将文件名命名为具体跟踪的PHP执行文件名、进程ID、随机数等,非常方便,更多的Xdebug配置选项说明,请参考官网的Xdebug配置选项说明。

  至此PHP调试工具Xdebug教程之Xdebug的安装和配置就介绍完了,今后还将陆续介绍Xdebug如何在zend studio以及editplus中配置使用。

  :PHP网站开发教程-leapsoul.cn版权所有,转载时请以链接形式注明原始出处及本声明,谢谢。



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles