Performance tuning is required in development, using XDEBUG Analysis thinkphp framework function call graph.
About Xdebug Installation reference these 2 articles
NetBeans Configuration xdebug Remote Debugging PHP
PHP Extended Xdebug installation and analysis with Kcachegrind system
1. Install Xdebug
Need to go to http://www.xdebug.org to look at some documents, xdebug as a php extension installation
# http://www.xdebug.org/files/xdebug-2.3.3.tgz
# TAR-XZF Xdebug-2.3.3.tgz
# CD xdebug-2.3.3
#/usr/local/php/bin/phpize
#./configure--enable-xdebug--with-php-config=/usr/local/php/bin/php-config
# Make && make install
2. Give Permission
# mkdir-p/tmp/xdebug
# chmod 755/tmp/xdebug
# chown Nobody:nobody/tmp/xdebug
3. Modify PHP configuration
modifying php.ini files
[Xdebug]
zend_extension= "Xdebug.so"
Xdebug.profiler_enable=on
Xdebug.trace_output_dir= "/tmp/xdebug"
Xdebug.profiler_output_dir= "/tmp/xdebug"
4. Restart PHP-FPM
# Killall PHP-FPM
#/ETC/INIT.D/PHP-FPM
5. Run PHP generate log
Once configured, running the PHP file will generate a log file like this under/tmp/xdebug
-rw-r--r--1 Nobody nobody 4615252 Oct 17:31 cachegrind.out.29293
6. Using Kcachegrind graphical analysis log
windows port of Kcachegrind
Download Address: Http://sourceforge.net/projects/precompiledbin/?source=typ_redirect
Each step of the function call is clearly seen:
The most serious problem is in execute, which is a lot of SQL queries. Called is the number of function calls.
Many optimization methods, using memcached or directly using the thinkphp of their own cache, this is the optimized diagram, obviously see called less.
Query caching
Http://document.thinkphp.cn/manual_3_2.html#query_cache
For data queries that do not require high timeliness, we can use query caching to improve performance without caching and fetching ourselves using caching methods.
The query caching feature supports all databases and supports all caching methods and expiration dates.
When using query caching, you only need to call the cache method of the model class, for example:
1. $Model->cache (True)->where (' Status=1 ')->select ();
SQL Resolution Cache
Http://document.thinkphp.cn/manual_3_2.html#sql_build_cache
In addition to the query cache, thinkphp also supports SQL resolution caching because of the ORM mechanism of thinkphp, all SQL is dynamically generated and then executed by the database driver.
So if your application has a large number of SQL query requirements, then you can turn on SQL resolution caching to reduce SQL resolution and improve performance. To turn on SQL resolution caching, you only need to set:
1. ' Db_sql_build_cache ' => true,
You can open the SQL creation cache for database queries, the default caching method is file mode, and XCache and APC caching is supported, and you only need to set:
1. ' Db_sql_build_queue ' => ' XCache ',
We know that the amount of query SQL for a project can be very large, so it is necessary to set the queue length under cache, for example, we want the SQL resolution cache to be no more than 20 records, you can set:
1. ' Db_sql_build_length ' =>,//SQL cache queue Length.
How profilers lie:the cases of gprof and Kcachegrind
For PHP application speed, speed up, and then speed. , part 2nd: Analyzing PHP applications to find, diagnose, and accelerate slow-running code