search
HomeBackend DevelopmentPHP Tutorial怎么调试php《转》
怎么调试php《转》Jun 13, 2016 am 11:39 AM
apacheeclipsephpxamppxdebug

如何调试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
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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),