程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php debug 調試工具

php debug 調試工具

編輯:關於PHP編程

其項目地址: php教程-debug-tools/">http://freshmeat.net/projects/php-debug-tools/
文件下載地址: http://freshmeat.net/urls/7c58ae3fecce5763e7546b958d36e082
目前是1.03版本


這裡偶的環境是window xp , apache2.2, php5.2+ zend optimizer,
這裡結合php debug tools的幫助文檔來講解,圖有些是摘自文檔.

一.安裝篇
安裝前的准備環境:必須得先裝x-debug,
至於怎樣安裝x-debug請看http://www.xdebug.org/docs/install

1. 從http://www.xdebug.org/download.php下載合適你的x-debug版本
2. 解壓dll文件到php安裝目錄下的ext目錄,如c:/php/ext/php_xdebug-2.0.4-5.2.8-nts.dll
3. 修改php.ini文件,加入下段:
-------------偶是變態的分割線,你看不見我------------------------
zend_extension = "c:/php/ext/php_xdebug-2.0.4-5.2.8-nts.dll"
xdebug.collect_includes = off
xdebug.default_enable = off

xdebug.dump_globals = off
xdebug.dump_once = off
xdebug.extended_info = off
-------------偶是變態的分割線,你看不見我------------------------
注:this example is for non-thread safe version. for the thread safe version change "zend_extension" to "zend_extension_ts"

安裝完畢,解壓php debug tools壓縮包裡的所有文件到網站發布目錄.
(假設發布目錄為c:www,那麼就在其新建一個debug目錄,把所有文件扔進去)

在浏覽器中輸入:http://localhost/debug/test1-debug.php
如果看見下圖則安裝成功.

二.調試篇
1.debug errors
如以下代碼:
復制代碼 代碼如下:
<?php
require './lib/debug.php';
function test($a, $b)
{
echo $asd;
}
test(10, 'abc');
?>


2.用debug()來調試
如以下代碼:
復制代碼 代碼如下:
<?php
require './lib/debug.php';
function test($args)
{
test_nested($args);
}
function test_nested($args)
{
debug($args);
// or: debug(get_defined_vars());
// or: debug();
}
test(array('id'=>123, 'str'=>'test'));
?>


3.用dump()或者dump_tofile()調試
如以下代碼:
復制代碼 代碼如下:
<?php
include_once './lib/dump.php';
function test5()
{
include './testdata/test0.php';
$test = array('int'=>1, 'float'=>2.0, 'float2'=>2.1);
dump($test, $_server);
}
function test1() { test2(); }
function test2() { test3(); }
function test3() { test4(); }
function test4() { test5(); }
test1();
?>


至於dump_tofile()一般在以下情形使用:
a.當你不想停止程序運行時
b.不是你不想顯示調式數據,而是你不能.比如當你在ajax請求狀態時.
c.你還想在多處地方調式

可參見debug目錄下的test7-dump_tofile.php

注:本人在運行dump()或者dump_tofile()時發現並不能出現php debug tool文檔中所述

這裡可以通過修改debug/lib/debug.php的代碼來更正.(因為dump_tofile()有調用到dump(),所以我們只需修改一處.
於149行處的
echo $pre;

修改成:

//edit by benben---start
echo '<script type="text/網頁特效">';
echo 'document.write(';
echo $pre;
echo ');';
echo '</script>';
//edit by benben---end

修正後的圖:

4.跟蹤代碼,查看系統性能
可以浏覽目錄下的test3-trace.php,之後點右下角的控制台就可以了.
具體可參照文檔.(文檔在壓縮包內的doc目錄下)
三,如何與項目結合?

先把php debug tool的解壓縮文件,放置於項目目錄,建個目錄就叫debug吧! : )
其實我們需要的只是幾個文件而已.
比如路徑為:c:wwwprojectnamedebug

之後,我們可以通過兩種方式來調試
第一種,可以在項目源碼中加入這麼一句:
include_once('./lib/debug.php');

例如以下:c:wwwprojectnamehellodebugindex.php
復制代碼 代碼如下:
<?php
include_once('./debug/lib/debug.php');

$faint = 'helloworld ,debuging';

debug($arrb);
?>


什麼?你不想每個頁面都寫這麼一句?
那麼看看第二種方法,
這裡也有兩種方式,
1.修改php.ini 加入以下內容(修改成你自身的目錄):
auto_prepend_file = "c:wwwprojectnamedebugauto_prepend.php"
auto_append_file = "c:wwwprojectnamedebugauto_append.php"

2.修改.htaccess文件(注:此方法偶沒試過,嘿嘿)
php_value auto_prepend_file "c:wwwprojectnamedebugauto_prepend.php"
php_value auto_append_file "c:wwwprojectnamedebugauto_append.php"

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved