PHP code Debugging Tools in Windows and Linux Xdebug installation and configuration _php example

Source: Internet
Author: User
Tags php debugger phpinfo zend

One, why need debugger?

Many PHP programmers debug using Echo, Print_r (), Var_dump (), printf (), and so on, but for programmers with richer development experience, they can often By outputting the value of a particular variable, you can tell whether the program is performing correctly, or even how efficient it can be (some time functions may be required, of course). So why do we need a special debugging program to monitor our program's operation? The answer to this question may well be left behind to reveal.

Second, what is Xdebug?

Xdebug is an open source PHP debugger (a debug tool) that you can use to track, debug, and analyze the state of your PHP program.

Third, Windows XDebug installation and configuration

1. Download xdebug binary file: http://www.xdebug.org/download.php
Please choose to download according to the PHP version, for example:

Copy Code code 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. Locate and open the php.ini file
3. If you have configured Zendoptimizer, you need to first shield the Zendoptimizer-related configuration, usually as follows:
Copy Code code as follows:
[Zend]
Zend_extension_manager.optimizer_ts= "Path\zendoptimizer-3.3.0\lib\optimizer-3.3.0″
Zend_extension_ts= "Path\zendoptimizer-3.3.0\lib\zendextensionmanager.dll"

Delete it or comment it out with a semicolon, such as:
Copy Code code as follows:
; [Zend]
; zend_extension_manager.optimizer_ts= "Path\zendoptimizer-3.3.0\lib\optimizer-3.3.0″
; zend_extension_ts= "Path\zendoptimizer-3.3.0\lib\zendextensionmanager.dll"

4. Add XDebug configuration. Refer to the following:
Copy Code code 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= "Path\xdebug"
Xdebug.profiler_enable=on
Xdebug.profiler_output_dir= "Path\xdebug"
Xdebug.collect_params=on
Xdebug.collect_return=on
Xdebug.remote_enable=on
Xdebug.remote_handler=dbgp
Xdebug.remote_host=localhost
xdebug.remote_port=9000

Description
The place above "path" needs to be modified 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. Here can not be loaded in a extension=php_xdebug.dll way, must be loaded in Zend way, otherwise installed on the phpinfo is not shown xdebug this item.
Xdebug.auto_trace=on;
To automatically open the "Monitoring function call process" of the work mode. This feature can output the monitoring information of function calls as files in the directory you specify. The default value for this configuration entry is off.
Xdebug.collect_params=on;
To open the feature that collects function parameters. The parameter values of the function call are included in the monitoring information of the Function procedure call. The default value for this configuration entry is off.
Xdebug.collect_return=on
To open the collection function return value function. The return value of the function is included in the monitoring information of the Function procedure call. The default value for this configuration entry is off.
Xdebug.trace_output_dir=
The path of the output file that sets the monitoring information for the function call.
Xdebug.profiler_enable=on
, open the Performance Monitor.
Xdebug.profiler_output_dir=
Setting the path of the output file of the performance monitoring information.

There are some more specific parameter settings, see: http://www.xdebug.org/docs-settings.php
5. Restart the Web server, such as Apache or IIS
6. View the output of the phpinfo, if you see the XDebug option, it indicates that the configuration was successful.
7. Debug information file view.
Running the PHP program locally will generate some debugging information in the set directory, including:
A. Function call process monitoring information file, file name format: TRACE.XXXXXX.XT. This file can be viewed directly, which contains information such as the time the function was run, the parameter value of the function call, the return value, the file and location. The content format is relatively intuitive.
B. Performance monitoring document, file name format: cachegrind.out.xxxxxxxx.
The file can also be viewed directly, but the information format is not easily understood by humans, and we can install the Wincachegrind software to read it in a format. Download installation methods refer to the following:
Download: http://sourceforge.net/projects/wincachegrind/
After downloading the installation run, then click Tools->options, set working folder (php.ini Xdebug.profiler_output_dir value)
This allows for a more intuitive view of the performance monitoring file information.

Four, Linux under the XDebug installation and configuration

Linux can download the source code compiled installation, the method reference below.
1. Download the corresponding PHP version of the source code source: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 code 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 Code code as follows:
sudo apt-get install Php5-dev

3. Move the xdebug.so file under PHP5
Copy Code code as follows:
CP modules/xdebug.so/usr/lib/php5/

4. Edit PHP.ini and add the following lines:
Copy Code code 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 to test for successful installation

If you see Xdebug in the output, the installation configuration is successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.