http://freshmeat.net/projects/php-debug-tools/ File download address: http://freshmeat.net/urls/7c58ae3fecce5763e7546b958d36e082 It is currently version 1.03"/> http://freshmeat.net/projects/php-debug-tools/ File download address: http://freshmeat.net/urls/7c58ae3fecce5763e7546b958d36e082 It is currently version 1.03">
Home > Article > Backend Development > php debug debugging tool_PHP tutorial
The project address: php tutorial-debug-tools/">http://freshmeat.net/projects/php-debug-tools/
File download address: http://freshmeat.net/urls/7c58ae3fecce5763e7546b958d36e082
Currently version 1.03
The environment here is window xp, apache2.2, php5.2+ zend optimizer,
This is explained in conjunction with the help documentation of php debug tools. Some of the pictures are excerpted from the documentation.
1. Installation
Preparation environment before installation: x-debug must be installed first,
As for how to install x-debug, please see http://www.xdebug.org/docs/install
1. Download the appropriate x-debug version from http://www.xdebug.org/download.php
2. Unzip the dll file to the ext directory under the PHP installation directory, such as c:/php/ext/php_xdebug-2.0.4-5.2.8-nts.dll
3. Modify the php.ini file and add the following paragraph:
-------------I am the dividing line of perversion, you can’t see me--------------------------
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
-------------I am the dividing line of perversion, you can’t see me--------------------------
Note: this example is for non-thread safe version. for the thread safe version change "zend_extension" to "zend_extension_ts"
After the installation is complete, unzip all the files in the php debug tools compressed package to the website publishing directory.
(Assuming the release directory is c:www, then create a new debug directory in it and throw all the files into it)
Enter in the browser: http://localhost/debug/test1-debug.php
If you see the picture below, the installation is successful.
2. Debugging
1.debug errors
Such as the following code:
Copy the code. The code is as follows:
require './lib/debug.php';
function test($a, $b)
{
echo $asd;
}
test(10, 'abc');
?>
2. Use debug() to debug
Such as the following code:
Copy the code. The code is as follows:
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. Use dump() or dump_tofile() to debug
Such as the following code:
Copy the code. The code is as follows:
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();
?>
As for dump_tofile(), it is generally used in the following situations:
a. When you don’t want to stop the program from running
b. It’s not that you don’t want to display debug data, but that you can’t. For example, when you request status in ajax.
c. You also want to adjust the style in multiple places
Please refer to test7-dump_tofile.php
in the debug directoryNote: When I ran dump() or dump_tofile(), I found that the php debug tool documentation did not appear
This can be corrected by modifying the code of debug/lib/debug.php. (Because dump_tofile() calls dump(), we only need to modify one place.
at line 149
echo $pre;
was changed to:
//edit by benben---start
echo '';
//edit by benben---end
Corrected picture:
4. Track code and check system performance
You can browse test3-trace.php in the directory, and then click the console in the lower right corner.
For details, please refer to the documentation. (The documentation is in the doc directory in the compressed package)
3. How to combine it with the project?
First unzip the php debug tool file and place it in the project directory. Create a directory and call it debug! : )
In fact, all we need is a few files.
For example, the path is: c:wwwprojectnamedebug
After that, we can debug in two ways
The first way is to add this sentence to the project source code:
include_once('./lib/debug.php');
For example: c:wwwprojectnamehellodebugindex.php
Copy the code. The code is as follows:
include_once('./debug/lib/debug.php');
$faint = 'helloworld ,debuging';
debug($arrb);
?>
What? You don’t want to write this sentence on every page?
Then take a look at the second method,
There are two ways here,
1. Modify php.ini and add the following content (modify to your own directory):
auto_prepend_file = "c:wwwprojectnamedebugauto_prepend.php"
auto_append_file = "c:wwwprojectnamedebugauto_append.php"
2. Modify the .htaccess file (Note: I have never tried this method, hehe)
php_value auto_prepend_file "c:wwwprojectnamedebugauto_prepend.php"
php_value auto_append_file "c:wwwprojectnamedebugauto_append.php"