First, installation configuration
1, download php xdebug extension, website: 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 of the path is not necessarily placed in the path, you can Zend_extension_ The location of the xdebug.so is specified in TS.
Reference
Vi/usr/local/php/lib/php.ini
Modify the php.ini, remove the PHP accelerator module, add the following configuration information to support Xdebug extension
View Plainprint?
[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, the first page on the various links click a few 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 execution took the longest time:
/usr/local/apache/htdocs/tag/tags.php Time Consuming 840ms
Third, the analysis results:
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 was called 21 times by the Filter_tags function from the/usr/local/apache/htdocs/include/misc.php,getforbiddentags function, Filter_ The majority of the time the tags function is caused by the getforbiddentags function. The contents of the Getforbiddentags function are as follows:
View Plainprint?
-
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, 1024x768);
-
$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) The Getforbiddentags function is analyzed, and the PHP function trim is called 16,827 times.
(5) Possible causes of bottlenecks:
The 156 keywords to filter are stored row by line in the/usr/local/apache/template/tags/forbidden_tags.txt file, and the text database is inefficient.
Line-by-row reading of the function fgets, and the removal of whitespace on either side of the string or the function trim of the specified character under high load is inefficient, you can test the fopen, Fread, fscanf and other file reading functions, compare.