Speaking of PHP code debugging, for experienced PHPer, PHP code debugging can be solved through echo, print_r, var_dump functions, or PHP development tools zendstudio and editplus. for experienced PHPer, most problems can be solved through echo, print_r, var_dump functions, or PHP development tools zend studio and editplus, but it is difficult for PHP beginners to learn, in addition, Xdebug is a very useful PHP debugging tool, and it is difficult to accurately identify PHP performance problems through the above PHP debugging methods.
Xdebug, as a PHP debugging tool, provides a wide range of debugging functions. you can also configure Xdebug installation as zend studio and editplus to debug third-party PHP plug-ins. by enabling auto_trace) and analyzer function, you can intuitively see the performance data of PHP source code, in order to optimize PHP code. Today, I will share with you the basic knowledge of installing and configuring the PHP debugging tool Xdebug.
The installation configuration of Xdebug in PHP involves the modification of the php. ini configuration file.
Xdebug installation tutorial
Download Xdebug
First, we need to download Xdebug. Be sure to select the appropriate Xdebug version based on the installed PHP version, because I installed PHP in Windows (refer to the tutorial on installing and configuring PHP + Apache + Mysql in Windows 7 ), so choose to download the Windows version of Xdebug2.1.0 (5.3 VC6 (32 bit), the downloaded Xdebug file for the php_xdebug-2.1.0-5.3-vc6.dll, this is because Xdebug is installed as a PHP module configuration and use.
Xdebug installation prompt: If you do not know the installed PHP version, you can refer to the phpinfo () function. Xdebug also provides the phpinfo output information analysis tool to help you analyze how to install Xdebug, copy and submit the phpinfo output information. Address: Xdebug phpinfo Information Analysis address.
Install Xdebug
Copy the downloaded php_xdebug-2.1.0-5.3-vc6.dll to the ext directory under the PHP installation directory, which is C: \ php \ ext, which is used to store the PHP Extension Library DLL file.
Configure php. ini
The last step to install Xdebug is to configure the php. ini file, open the php. ini configuration file under the C: \ php directory, and add
1 2
|
[Xdebug] Zend_extension = "c:/php/ext/php_xdebug-2.1.0-5.3-vc6.dll" |
Restart the Apache server and use the phpinfo () function.
PHP Xdebug configuration information
Xdebug configuration prompt: Zend_extension_ts is used when Xdebug is configured in versions earlier than PHP5.3. for PHP5.3 and later versions, zend_extension is used.
Reason why xdebug not loaded as zend extension information appears
The reason why xdebug not loaded as zend extension occurs is that when Xdebug is installed, we copy the Xdebug DLL file to the php \ ext directory, and it is easy to load Xdebug AS a php extension Library, in php. ini file added
1
|
Extension = php_xdebug-2.1.0-5.3-vc6.dll |
This is an incorrect Xdebug installation method and must be loaded in zend mode.
Now the PHP Xdebug basic installation tutorial is complete. below we need to make some basic configuration for Xdebug.
Xdebug Configuration tutorial
After installing Xdebug, we also need to make basic configuration for Xdebug. by default, the PHP function auto-tracking (auto_trace) function and analyzer function of Xdebug are not enabled, which is required for debugging PHP code, some Xdebug configuration options are recommended to be enabled.
Before that, we need to create an Xdebug automatic tracking directory and a directory for storing the output file of the analyzer. make sure that the directory is read and written. here I am at D: the xdebug \ trace and xdebug \ profiler directories are created under \ PHPWeb.
Finally, complete the Xdebug configuration in the php. ini configuration file and find
1 2
|
[Xdebug] Zend_extension = "c:/php/ext/php_xdebug-2.1.0-5.3-vc6.dll" |
After that, add the Xdebug configuration information
1 2 3 4 5 6
|
Xdebug. auto_trace = 1 Xdebug. collect_params = 1 Xdebug. collect_return = 1 Xdebug. trace_output_dir = "D:/PHPWeb/xdebug/trace" Xdebug. profiler_enable = 1 Xdebug. profiler_output_dir = "D:/PHPWeb/xdebug/profiler" |
Finally, save php. ini and restart the Aapche server.
Configuration options in Xdebug
Xdebug. auto_trace = 1
Whether to allow Xdebug to trace function calls. trace information is stored as files. the default value is 0.
Collect_params = 1
Whether to allow Xdebug to trace function parameters. the default value is 0.
Xdebug. collect_return = 1
Whether to allow Xdebug to trace function return values. the default value is 0.
Xdebug. profiler_enable = 1
Open the xdebug performance analyzer and store it as a file. this configuration cannot be configured using the ini_set () function. the default value is 0.
Xdebug. profiler_output_dir
Storage location of performance analysis files; default value:/tmp
Xdebug. profiler_output_name
Naming rules for performance analysis files. the default value is cachegrind. out. % p.
Xdebug. trace_output_dir
Directory of the output file of the function call trace information. the default value is/tmp.
Xdebug. trace_output_name
Naming rules for output file of function call trace information. the default value is trace. % c.
Note: Xdebug trace and profiler output file name rules can be changed. for example, naming a file name as the PHP execution file name, process ID, and random number of a specific trail is very convenient, for more instructions on Xdebug configuration options, refer to the instructions on Xdebug configuration options on the official website.
Now, the installation and configuration of Xdebug in the Xdebug tutorial of PHP debugging tool is complete. in the future, we will introduce how to configure and use Xdebug in zend studio and editplus.