Installation of xdebug-(executable version without errors)

Source: Internet
Author: User
Tags php debugger stack trace vc9

Xdebug is an open-source PHP debugger that is loaded and used as a PHP module. It can be used to track, debug, and analyze the running status of PHP programs.

Php5.2.13 is used as an example,

1. Download The php_xdebug-2.1.0-5.2.dll file,

Http://www.xdebug.org/download.php

Select: PhP 5.2 vc6 TS (32 bit)

Choose vc6 or vc9?

Indicates that msvc9 (Visual C ++ 2008) is vc9
If you use PHP in apache1 or apache2, you should select vc6.
If you use PHP in IIS, you should select the version of vc9.
The vc6 version is compiled using Visual studio6
Vc9 is compiled using Visual Studio 2008 and improves performance and stability. For PHP of vc9, you need to install Microsoft 2008 C ++ runtime.
Do not use vc9 in Apache

2. Rename the file php_xdebug.dll and place it in the ext directory under the PHP installation directory.

3. Modify the php. ini file

Add the code to the file

[Xdebug]
Zend_extension_ts = "C: // PHP/EXT/php_xdebug-2.1.2-5.2-vc6.dll"

Xdebug. collect_params = on
Xdebug. collect_return = on
Xdebug. trace_output_dir = "F: \ phpweb \ xdebug" // set the path of the output file of function call monitoring information.
Xdebug. profiler_enable = on // enable the Performance Monitor.
Xdebug. profiler_output_dir = "F: \ phpweb \ xdebug" // set the path of the performance monitoring information output file.

 

4. Restart Apache

 

5. Test and create a test. php

The content is <? PHP phpinfo ();?>

 

If xdebug is displayed in the output, the installation and configuration are successful.

 

Note phpinfo ();

Write the following code to intentionally cause an exception:

      <?phprequire_once("abc.php");?>

Refresh the webpage:

Then, we were surprised to find that the error information was colored:

However, apart from style changes, the error information we usually print is no different and does not make much sense. Okay. Let's rewrite the program:

<?phptestXdebug();function testXdebug() {       require_once('abc.php');}?>

Refresh the webpage:

What have you found? Xdebug tracks code execution and finds the function testxdebug () with an error ().
The code is more complex:

<?phptestXdebug();function testXdebug() {       requireFile();}function requireFile() {       require_once('abc.php');}?>

Refresh the webpage:

Xdebug is similar to Java exception's "tracing and tracing" function. It can track errors step by step based on program execution, even if the calls in the program are complex, we can also use this function to clarify the code relationship, quickly locate the problem, and quickly troubleshoot the problem.

Additional reading:

Xdebug Configuration

Part 1: basic features:
Related parameter settings
Xdebug. default_enable
Type: Boolean default value: On
If this parameter is set to on, the stack trace is displayed in the error event by default. You can use xdebug_disable () in the code to disable the display of stack trace. This is one of the basic functions of xdebug. it is wise to set this parameter to on.
Xdebug. max_nesting_level
Type: integer; default value: 100
The value of this setting is the maximum level of nested functions that are allowed before the script will be aborted.
Limit infinite recursive access depth. The value of this parameter is the maximum access depth allowed by the nested program before the script fails.

Part 2: Stack tracing:
Related parameter settings
Xdebug. dump_globals
Type: Boolean default value: 1
Restrict whether to display the value of the hyperglobal variable defined by xdebug. Dump. *.
For example, xdebug. dump. server = request_method, request_uri, http_user_agent prints the PHP hyper-global variables $ _ server ['request _ method'], $ _ server ['request _ URI '], and $ _ server ['HTTP _ user_agent'].
Xdebug. dump_once
Type: Boolean default value: 1
The value that limits whether the global variable is exceeded should be dumped in all error environments (when set to off) or just at the beginning (when set to on)
Xdebug. dump_undefined
Type: Boolean default value: 0
If you want to dump undefined values from the Super global variable, you should set this parameter to on; otherwise, it will be set to off.
Xdebug. show_exception_trace
Type: integer default value: 0
When this parameter is set to 1, xdebug enforces exception tracking even if an exception is caught.
Xdebug. show_local_vars
Type: integer default value: 0
When this parameter is set to not equal to 0, the stack dump generated by xdebug in the error environment will also display all local variables, including uninitialized variables at the top. Note that this will generate a large amount of information, so it is disabled by default.

Part 3: Analysis of PHP scripts
Related parameter settings
Xdebug. profiler_append
Type: integer default value: 0
When this parameter is set to 1, the file will not be appended when a new requirement is sent to the same file (depending on the xdebug. profiler_output_name setting ). Otherwise, the file will be appended to a new file.
Xdebug. profiler_enable
Type: integer default value: 0
The permission to open the xdebug file is to create a file in the file output directory. These files can be read by kcachegrind to show your data. This setting cannot be set by calling ini_set () in your script.
Xdebug. profiler_output_dir
Type: String default value:/tmp
This file is written by the profiler file output. You are sure that the PHP user has the write permission on this directory. This setting cannot be set by calling ini_set () in your script.
Xdebug. profiler_output_name
Type: String default value: cachegrind. Out % P
This setting determines the name of the file written by the dump trace.

Part 4: Remote debug
Related parameter settings
Xdebug. remote_autostart
Type: Boolean default value: 0
Generally, you need to use a clear http get/post variable to enable remote debug. When this parameter is set to on, xdebug often tries to enable a remote debug session and try to connect to the client, even if the get/post/cookie variable is not the current one.
Xdebug. remote_enable
Type: Boolean default value: 0
This switch controls whether xdebug should try to connect to a debug client that listens to the host and port according to xdebug. remote_host and xdebug. remote_port.
Xdebug. remote_host
Type: String default value: localhost
Select the host on which the debug client is running. You can use not only the host name but also the IP address.
Xdebug. remote_port
Type: integer; default value: 9000
This port is used by xdebug to connect to the remote host. 9000 is the default port between the client and the bound debug client. Many clients use this port number. It is best not to modify this setting.
Note: After all the preceding parameters are modified, restart Apache to take effect!

Xdebug debugging
In fact, the PHP function debug_backtrace () has similar functions, but note that the debug_backtrace () function is only available in Versions later than php4.3.0 and
PhP5 takes effect only. This function is a new function added by the php development team in PhP5, and is then reversely transplanted to php4.3.
Xdebug makes debugging information more beautiful
After the xdebug extension is loaded, xdebug will overwrite some of the original PHP functions for better debugging. For example, for the var_dump () function, we know that we usually need to add "<PRE>... </PRE> "to make the output variable information more beautiful and readable. However, after xdebug is loaded, we no longer need to do so. xdebug not only automatically adds the <PRE> label to us, but also adds color to the variables.
Example:
<? PHP
$ Arrtest = array (
"Test" => "ABC ",
"Test2" => "abc2"
);
Var_dump ($ arrtest );
?>
Output:

Have you seen it? The value of the array element is automatically colored.
If you still want to use the var_dump function of PHP, you only need to add xdebug. overload_var_dump = off to the xdebug configuration of PHP. ini.
Xdebug test script execution time
To test the execution time of a script, we usually need to use the microtime () function to determine the current time. Example in the PHP manual:
<? PHP
/**
* Simple function to replicate PHP 5 behaviour
*/
Function microtime_float ()
{
List ($ USEC, $ Sec) = explode ("", microtime ());
Return (float) $ USEC + (float) $ Sec );
}
$ Time_start = microtime_float ();
// Sleep for a while
Usleep (100 );
$ Time_end = microtime_float ();
$ Time = $ time_end-$ time_start;
Echo "did nothing in $ time seconds \ n ";
?>
However, the values returned by microtime () are microseconds and absolute timestamps (for example, "0.03520000 1153122275"), which are not readable. Therefore, for the above program, we need to write another function microtime_float () to add the two.
Xdebug comes with the xdebug_time_index () function to display the time.

Memory occupied by PHP scripts
Sometimes we want to know how much memory is occupied when the program is executed to a specific stage. For this reason, PHP provides the memory_get_usage () function (). This function is valid only when the -- enable-memory-limit parameter is used during PHP compilation.
Xdebug also provides the xdebug_memory_usage () function to implement this function. In addition, xdebug also provides an xdebug_peak_memory_usage () function to view the peak memory usage.

Wincachegrind
Sometimes the Code has no obvious writing errors and no error information (such as error, warning, or notice) is displayed, but this does not indicate that the code is correct. Sometimes it may take too long to execute a piece of code, occupying too much memory, which affects the efficiency of the entire system. We cannot directly see which part of the Code has a problem. At this time, we hope to monitor the running status of each stage of the Code, write it to the log file, and analyze it after running for a period of time to locate the problem.
Recall that we edited the php. ini file.
Join
[Xdebug]
Xdebug. profiler_enable = on
Xdebug. trace_output_dir = "I: \ projects \ xdebug"
Xdebug. profiler_output_dir = "I: \ projects \ xdebug"
These lines are used to write the execution analysis file to the "I: \ projects \ xdebug" Directory (you can replace it with any directory you want to set ). If you open the corresponding directory after executing a certain sequence, you can find that a bunch of files are generated, such as files named in the format of cachegrind. out.1169585776. These are the analysis files generated by xdebug. Open it in the editor and you can see a lot of details about the program running, but obviously this is too tired, we need to use graphical software to view.
Download wincachegrind
On Windows, you can use wincachegrind (wincachegrind.souceforge.net) to open these files. You can visually and beautifully display the content:

Wincachegrind summary:
Xdebug provides various built-in functions and overwrites some existing PHP functions to facilitate debugging and troubleshooting. xdebug can also track program running, by analyzing log files, we can quickly find the bottleneck of program running, improve program efficiency, and thus improve the performance of the entire system.

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.