First, installation configuration
1, download php xdebug extension, url: http://xdebug.org/
2. Compile and install Xdebug under Linux
Reference
Tar-xzf xdebug-2.0.0rc3.gz
CD XDEBUG-2.0.0RC3
/usr/local/php/bin/phpize
./configure--enable-xdebug
CP modules/xdebug.so/usr/local/php/lib/php/extensions/no-debug-non-zts-20020429/
Note:/usr/local/php/lib/php/extensions/no-debug-non-zts-20020429/different PHP version paths are not necessarily placed in the path, can be in the Zend_extension_ The TS specifies the location of the xdebug.so.
Reference
Vi/usr/local/php/lib/php.ini
Modify php.ini, remove PHP acceleration module, add the following configuration information to support Xdebug extension
Copy Code code as follows:
[Xdebug]
Zend_extension_ts= "/usr/local/php/lib/php/extensions/no-debug-non-zts-20020429/xdebug.so"
Xdebug.profiler_enable=on
Xdebug.trace_output_dir= "/tmp/xdebug"
Xdebug.profiler_output_dir= "/tmp/xdebug"
Xdebug.profiler_output_name= "Script"
Reference
Mkdir-p/tmp/xdebug
chmod 755/tmp/xdebug
Chown Www:www/tmp/xdebug
/usr/local/apache/bin/apachectl-k restart
3. Client (Windows): Wincachegrind
Download Address: http://sourceforge.net/projects/wincachegrind/
Second, the analysis process
1. Visit your website and click on the various links on the home page several times, xdebug in the/tmp/xdebug directory to generate the following files:
Usr_local_apache_htdocs_app_checknum_chknum_php_cachegrind.out
Usr_local_apache_htdocs_app_login_showheaderlogin_php_cachegrind.out
Usr_local_apache_htdocs_app_play_play_php_cachegrind.out
Usr_local_apache_htdocs_app_user_member_php_cachegrind.out
Usr_local_apache_htdocs_tag_tags_php_cachegrind.out
Usr_local_apache_htdocs_top_top_php_cachegrind.out
2, copy the above files to Windows, with the client software Wincachegrind open each file, found that the following PHP program to execute the longest time:
/usr/local/apache/htdocs/tag/tags.php Time Consuming 840ms
Third, the results of analysis:
1,/usr/local/apache/htdocs/tag/tags.php
(1) The longest-consuming filter_tags function appears on line 158th of/usr/local/apache/htdocs/tag/tags.php:
$tags. = Filter_tags ($videos [$i] [' tags ']). " ";
(2) The Filter_tags function is invoked 21 times by the Filter_tags function from the/usr/local/apache/htdocs/include/misc.php,getforbiddentags function, Filter_ The tags function consumes most of the time due to the Getforbiddentags function. The contents of the Getforbiddentags function are as follows:
Copy Code code as follows:
function Getforbiddentags ()
{
$tagsPath =template_file_path. " Tags/forbidden_tags.txt ";
if (file_exists ($tagsPath))
{
$fp = fopen ($tagsPath, "R");
$arrconf = Array ();
if ($FP)
{
while (!feof ($FP))
{
$line = fgets ($fp, 1024);
$line = Trim ($line);
$rows = Explode ("#", $line);
$coumns = explode ("=", Trim ($rows [0]));
if (""!=trim ($coumns [0]))
{
$arrconf [Trim ($coumns [0])] = Trim ($coumns [1]);
}
}
}
return $arrconf;
}
}
(4) Analysis of the Getforbiddentags function, in which the PHP function trim was called 16,827 times.
(5) Possible causes of bottlenecks:
The 156 keywords to be filtered are stored in/usr/local/apache/template/tags/forbidden_tags.txt files on a line-by-row basis, and the text database is inefficient.
Reading function fgets by line, and removing whitespace on either side of the string or the specified character's function trim is inefficient at high load, and can be tested for file reading functions such as fopen, Fread, fscanf, and contrast.