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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
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)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles