Today I'm going to share a little bit of my experience with Xdebug. Xdebug is also because the need is used to generate coverage analysis files installed, just contact soon, usually used is not very frequent, but this is a good tool, if you want to rely on it to analyze the performance of the program or need to try their own hands. How good it is, please listen to me one by one.
<!--[if!supportlists]--> <!--[endif]--> installation article (XDebug and PHPUnit )
A : Install XDebug:
Xdebug Network download xdebug dll file, stored in PHP loaded ext directory (you can choose to rename, such as Php_xdebug.dll, and then open php.ini file, add configuration
[Xdebug]
Zend_extension_ts = Php_xdebug.dll
Xdebug.profiler_enable = On
Xdebug.trace_output_dir = D:\PHPAPP\XDebug
Xdebug.profiler_output_dir=d:\phpapp\xdebug
Xdebug need to be loaded by the Zend engine, so zend_extension_ts or zend_extension, TS is thread_safety, currently more than 5.3 to support zend_extension load,< 5.3 is loaded with zend_extension_ts (or you can see if Phpinfo is enabled Zts), and then reboot Apache, see Phpinfo, and find the Xdebug option.
You can see xdebug.profiler_enable,xdebug.profiler_output_dir,xdebug.trace_. Output_dir These three are the items that we just configured, we can install their own needs to configure the remaining items,xdebug.profiler_enable: Open performance analysis,
After this, the Cachegrind.out.XXX analysis file is generated in the Xdebug.profiler_output_dir directory, and if Xdebug.profiler_output_name is specified, The output file will be the specified name. xxx Format (this method is not suitable for analysis, explained later),
xdebug.trace_options : This is the open tracking item,
After the item is opened, the trace file is produced under Xdebug.trace_output_dir, noting that it affects the speed at which it is run because he needs to record a series of events during the tracking process.
There is one more thing to note about XDebug : XDebug is debug, that is, configure the XDebug the program is running a debug state, So at this time Zend_optimizer can not use, always can not let the program that is debugging state and in the optimization State ha.
More about the XDebug , we go online to explore it ~ ~ then together to discuss Ha
Friendly reminder: for the use of integrated environment of students, such as WAMP, it has two php.ini configuration files, one under the Apache, one in PHP, under Apache is the impact of the web, and PHP under the influence of the command line, so (Thanks for June Brother's reminder)
B : Install PHPUnit:
About the installation process of PHPUnit, the internet has also been a lot, before their own in order to finally successfully installed after the small text of the installation of the article (http://user.qzone.qq.com/414073277/blog/1292122868), so here is no longer to repeat, Most of the installation tutorials on the Web can be completed. The process is simple:
PHPUnit installation is the Pear installation method, so if the machine has not been installed Pear package needs to be installed first, generally in the installation of PHP installed in the directory has a go-pear.bat file, directly executed to complete the installation, "here to install the need to pay attention to expand EXIF, This extension uses the method in the mbstring extension, so the loading order of the mbstring needs to be above EXIF. "After you finish installing pear, you can execute pear, see the command parameters of pear,
Then execute sequentially:
Pear Channel-discover pear.phpunit.de
Pear install–alldeps Phpunit/phpunit
It should be noted that the latest version of the PHPUnit is 3.5 But this only pear version is more than 1.6 and php5.2.x will be installed to get the latest version of the installation is otherwise installed is the first version (but does not affect the use).
Once installed, you can perform phpunit to view related information:
You can see that the three options for-coverage-html–coverage-clover–coverage-source are available only after the Xdebug installation is successful, and these three are important options for exporting coverage files.
<!--[if!supportlists]--> II<!--[endif]-->PHPUnit Unit test Coverage Analysis
Unit test, one of the most important indicators is coverage. This point although Zend Studio can be very clear to see, but to export into a document is not very good, so this time Xdebug can also help the busy, the use of a very simple, call the command can:
phpunit–coverage-html D:\PHPAPP\XDebug\ Youtest
This will put the resulting overlay file (HTML) in the D:\PHPAPP\XDebug\ directory,
Then you can find a bunch of HTML files in the directory below and run the next index.html
You can see such a picture, the English alphabet is very simple · The meaning is clear and does not explain the point:
The test results show that there are 5 kinds, the example above shows two kinds.
. : Represents the correct
F: Represents an assertion error
E: Represents a PHP program error or exception
I: Represents a method that is not implemented
S: Represents a skipped method
Description of the production coverage document:
Classes: When all the methods in a class are overwritten, this class is tested
Functions/methods: Only one method or function of all valid statement code is executed to the method or the function is tested
Lines: The total number of rows will be filled with comments, blank lines, <?php?> labels, and declarations of classes and methods.
Using Phpunit–coverage-clover D:\PHPAPP\XDebug\first.xml youtest
Production will be an XML format file, this format of the file effect is not obvious, there is no good HTML format, this side of the effect was I deleted, so there is the effect of the picture can be seen, the third overwrite the parameters of the file I have not tested, we are interested to try.
<!--[if!supportlists]--> III<!--[endif]--> program Performance Analysis
In addition to the effective analysis of unit test coverage, XDEBUG can help group analyze the bottleneck of program execution, and open the function of analysis:
Xdebug.profiler_enable = On
Xdebug.profiler_output_dir=d:\phpapp\xdebug
Set the above two items, and then execute the program you want to analyze, Will be in the above directory to see Cachegrind.out.XXX file, this file directly open is some records, need to use the Third-party cachegrind view tools, a useful tool is wincachegrind, look very convenient.
You can see the total time of execution, and the time each function executes.
Because this tool can only open cachegrind.out.* files when the file is opened, so the file to be analyzed must be the name, so in order to omit renaming, this is why I said that it is not recommended to modify the Xdebug.profiler_output_ Name the reason for this option.
<!--[if!supportlists]--> IV<!--[endif]--> XDebug Library functions
Xdebug In addition to the above methods, there are some of their own function library to provide, can be in the Code section of your program to execute anywhere, specific please see http://xdebug.org/docs/all_functions
Xdebug's features, and more than that, because his options are a great one page, so still go to http://xdebug.org/docs/here to see the official instructions. Unreliable