php debug 調試工具

來源:互聯網
上載者:User

其項目地址: 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"

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.