Home Backend Development PHP Tutorial 怎么调试php《转》

怎么调试php《转》

Jun 13, 2016 am 11:39 AM
apache eclipse php xampp xdebug

如何调试php《转》

一个好的代码调试器可以让你在解决问题的时候事半功倍,因为代码调试器可以设置断点,可以逐行逐行代码进行跟踪,可以查看变量的值等等优点。每一种开发语言都有很好的代码调试器,PHP也不例外,Xdebug、Zend Debugger等都是十分好的php调试工具,本文将为您展示如何用eclipse+pdt+xdebug来调试php网站。

?

1.工具准备

?

eclipse,地球上的软件开发人员都知道能用它来开发java项目,其实还可以用它来开发php网站,点击这里下载集成了pdt的eclipse版本。选择适用于您的操作系统的进行下载。

php+apache,这两种工具只需要安装集apache、php、mysql、phpMyAdmin等于一身的xampp即可,如果您不知道如何安装和使用xampp,请阅读《如何安装xampp》和《如何安装部署php网站》。

Xdebug,如果您使用的是xampp,那么你无须下载xdebug,因为它已经集成了,你只需要在xampp的php.ini文件开启xdebug就行了。如果您没有使用xampp,那么你一定要选择合适您php版本的xdebug,否则会集成不成功的,如何知道要下载什么版本的xdebug?首先先创建一个php文件,里面的代码为,然后部署到php下运行,查看php的相关信息,把所有信息复制到xdebug官方的分析工具页面进行分析,它会给出您的php对应的分析结果,提示您下载对应版本的xdebug。

?

2.配置eclipse pdt

?

下载eclipse for php developers后,解压就可以使用了,打开后eclipse工具后就可以配置php和xdebug的相关信息了。

window->Preferences->php,

phpeclipse1

如何调用php网站1

先配置php运行程序

phpeclipse2

如何调用php网站2

配置运行环境

phpeclipse3

如何调用php网站3

选择php版本

phpeclipse4

如何调用php网站4

配置服务器

phpeclipse5

如何调用php网站5

配置xdebug

phpeclipse6

如何调用php网站6

?

3.配置php,集成xdebug

?

如果您没有安装xampp,那么您就需要先下载你与您安装的php版本对应的xdebug,具体做法在第一点工具准备中已经说明,如果您已经安装了xampp,那么恭喜您,你只需要开启xdebug就行,具体做法就是打开php.ini,然后搜索Xdebug,找到后把zend_extension前的;去掉,把=号右面的路径改为”D:\xampp\php\ext\php_xdebug.dll”,(注:路径要修改为您自己安装的目录),然后把以下几个选项前的;也去掉,并把=号右面的值改与下面的一致

xdebug.remote_enable=On

xdebug.remote_host=”localhost”,注:这里的localhost改为你的服务器对应的IP

xdebug.remote_port=9000

xdebug.remote_handler=”dbgp”

?

4.配置apache

?

通过配置apache服务器可以实现将访问路径映射到你本地的php网站程序目录,如果您安装了xampp,那么只需要修改apache\conf\extra目录下的httpd-xampp.conf文件,在标签内增加以下的代码:

Alias /phpip “D:/phpworkspace/HelloWorld/”

Options Indexes FollowSymLinks Includes ExecCGI

AllowOverride all Order allow,deny

Allow from all

其中,/phpip改为您想在浏览器中输入访问到项目的名称,D:/phpworkspace/HelloWorld/改为您程序对应的目录。

?

5.设置断点并调试

?

在eclipse中设置php调试断点,然后在浏览器中输入“http://servername/phpname/调试的文件”进行访问,servername是您的服务器的地址,phpname是您在apache中设置的php项目名。eclipse会提示是否打开调试控制面板,如下图:

phpeclipse7

如何调试php网站7

接着可以逐行代码进行调试

phpeclipse8

如何调试php网站8

在Debug output面板还可以查看网页浏览输出

phpeclipse9

如何调试php网站9

实际访问网页结果

phpeclipse10

如何调试php网站10

到此,你已经学会如何调试php,赶快试试吧。

?

原文地址:http://www.laokboke.net/2011/05/09/how-to-debug-php-using-xdebug/

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
1665
14
PHP Tutorial
1270
29
C# Tutorial
1250
24
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.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

NGINX and Apache: Understanding the Key Differences NGINX and Apache: Understanding the Key Differences Apr 26, 2025 am 12:01 AM

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

See all articles