1. Why do you need Debugger?
Many PHP programmers use echo, print_r(), var_dump(), printf(), etc. for debugging. In fact, these are enough for programmers with rich development experience. They can often perform debugging during program execution. In , by outputting the value of a specific variable, you can determine whether the program is executed correctly, and even the efficiency can be seen (of course, you may also need to use some time functions). So why do we need a special debugger to monitor the operation of our program? The answer to this question might as well be left to be revealed later.
2. What is Xdebug?
Xdebug is an open source PHP program debugger (i.e. a Debug tool) that can be used to track, debug and analyze the running status of PHP programs.
3. XDebug installation and configuration under Windows
1. Download the XDebug binary file: http://www.xdebug.org/download.php
Please choose to download according to the php version, for example:
Copy code The code is as follows:
5.2 http://www.xdebug.org/files/php_xdebug-2.1.2-5.2-vc6.dll
5.3 http://www.xdebug. org/files/php_xdebug-2.1.2-5.3-vc6.dll
2. Find and open the php.ini file
3. If ZendOptimizer has been configured, you need to block ZendOptimizer related configuration first, usually as follows :
Copy code The code is as follows:
[Zend]
zend_extension_manager.optimizer_ts=”pathZendOptimizer-3.3.0libOptimizer-3.3.0 ″
zend_extension_ts=”pathZendOptimizer-3.3.0libZendExtensionManager.dll”
Delete it or comment it out with a semicolon, such as changing it to:
Copy code The code is as follows:
;[Zend]
;zend_extension_manager.optimizer_ts=”pathZendOptimizer-3.3.0libOptimizer-3.3.0″
;zend_extension_ts=”pathZendOptimizer-3.3.0libZendExtensionManager. dll”
4. Add XDebug configuration. The reference is as follows:
Copy the code The code is as follows:
[Xdebug]
zend_extension_ts=”path/xdebug/php_xdebug-2.1.2 -5.2-vc6.dll”
xdebug.auto_trace=on
xdebug.trace_output_dir=”pathxdebug”
xdebug.profiler_enable=on
xdebug.profiler_output_dir=”pathxdebug”
xdebug.collect_params= on
xdebug.collect_return=on
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
Note:
The "path" above needs to be changed to your own local path.
Parameter explanation:
Copy code Code As follows:
zend_extension_ts=”c:/webserver/php5/ext/php_xdebug.dll”
; Load the xdebug module. You cannot load it here with extension=php_xdebug.dll. You must load it with zend. Otherwise, phpinfo will not display the xdebug item after installation.
xdebug.auto_trace=on;
;Automatically turn on the "monitoring function call process" function mode. This function can output the monitoring information of function calls in the form of a file in the directory you specify. The default value of this configuration item is off.
xdebug.collect_params=on;
;Turn on the function of collecting "function parameters". Include the parameter values of the function call in the monitoring information of the function procedure call. The default value of this configuration item is off.
xdebug.collect_return=on
; Turn on the function of collecting "function return value". Include the return value of the function in the monitoring information of the function procedure call. The default value of this configuration item is off.
xdebug.trace_output_dir=
; Set the path to the output file of function call monitoring information.
xdebug.profiler_enable=on
; Turn on the performance monitor.
xdebug.profiler_output_dir=
; Set the path to the performance monitoring information output file.
There are also some more specific parameter settings, see: http://www.xdebug.org/docs-settings.php
5. Restart the web server, such as Apache or IIS
6. Check the output of phpinfo. If you see the XDebug option, it means the configuration is successful.
7. View the debugging information file.
Running the PHP program locally will generate some debugging information files in the set directory, mainly including:
a. Function call process monitoring information file, file name format: trace.××××× ×.xt. This file can be viewed directly, and it contains information such as the running time of the function, parameter values of the function call, return value, file and location, etc. The content format is relatively intuitive.
b. Performance monitoring file, file name format: cachegrind.out.××××××××.
The file can also be viewed directly, but the information format is not easy for humans to understand. We can install the wincachegrind software to read it in a formatted format. The download and installation method is as follows:
Download: http://sourceforge.net/projects/wincachegrind/
After downloading, install and run, then click Tools->options, set the working folder (xdebug. in php.ini. profiler_output_dir value)
This way, you can view the information of the performance monitoring file more intuitively.
4. XDebug installation and configuration under Linux
You can download the source code, compile and install it under Linux. The method is as follows.
1. Download the source code source corresponding to the php version: http://www.xdebug.org/download.php
For example, xdebug-2.1.2.tgz version: http://www.xdebug.org/ files/xdebug-2.1.2.tgz
2. Compile and install
Copy code The code is as follows:
tar -xvzf xdebug- 2.1.2.tgz
cd xdebug-2.1.2
./configure
make
make install
If there is an error phpize does not have this command, then install it:
Copy the code The code is as follows:
sudo apt-get install php5-dev
3. Move the xdebug.so file to php5 Copy the code below
The code is as follows:
cp modules/xdebug.so /usr/lib/php5/
4 . Edit php.ini and add the following lines:
Copy the code The code is as follows:
[Xdebug]
zend_extension= /usr /lib/php5/xdebug.so
xdebug.profiler_enable=on
xdebug.trace_output_dir=”../xdebug”
xdebug.profiler_output_dir=”../xdebug”
5. Restart Apache and test whether the installation is successful
If xdebug is seen in the output, the installation and configuration are successful.
http://www.bkjia.com/PHPjc/767087.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/767087.htmlTechArticle1. Why do you need Debugger? Many PHP programmers use echo, print_r(), var_dump(), printf( ), etc. In fact, these are enough for programmers with rich development experience...