How to quicken up Yii powered sites.

hi *

thanks to Yii, main modules of my site are done. now it looks like a real website. :lol:

but unfortunately it starts up very slow (taking about 2-3 seconds to load the frontpage), and the response to subsequent requests are also slow (also 2-3 seconds).

i was wondering if experienced yii developer can enlighten me how to make it run faster.

perhaps i need to use memcache or some caching software?

perhaps i need to use a kind of benchmark software to see what codes are slowing me down?

what principles in development should i follow to get a final quick site? (e.g unset used $model and $dataProviders?)

thanks for your precious revelation.

I would suggest the following steps

  1. Use profiling to find expensive database queries:Profiling Some may even be unnecessary

  2. Enable schema caching: http://www.yiiframework.com/doc/api/1.1/CDbConnection#schemaCachingDuration-detail

  3. Enable APC cache for opcode caching and data caching (it is faster than memcached if you are using a single machine - that’s at least my experience).

  4. Try using DAO for READING tons of models when you have to display them in a view for example. ActiveRecord is better suited for create/update operations than reading operations with large resultsets

  5. Use fragment caching to cache parts of your site that are loaded frequently but hardly change

Some additional stuff can be the use of CCacheHttpSession and minimizing script files like explained in

http://www.yiiframework.com/doc/guide/1.1/en/topics.performance#using-caching-techniques

Check the "performance tuning" in the guide - http://www.yiiframework.com/doc/guide/1.1/en/topics.performance

thank you, Haensel and Mdomba, i will check the items you suggested one by one.

but by the way, is it a good practice to use different view files for the different logic branches in a same action, than to implement the logic branches in the same view file? the balance is that, 2 view files result in additional file IO but 1 view file would be a twisted and bunting view file.

for example, is it good to write 2 different view files for authenticated users and guest users and render them accordingly in the controller?

you have to use mongodb suite extension or rediscache to cache your database including php and other scripts.

How much memory your website consume?

it’s not deployed yet and resides in localhost.

how do i check to see the memory consumption?

Yii Apprentice - in the extensions you have few extension for this…

Or the simplest way is echo


Yii::getLogger()->getMemoryUsage()

thanks Dckurushin, this function call returns 6608584 (other pages are also around 6000000), a large amount of memory consumption?

Yii Apprentice - depends if you use op code cache or not

if not, it is not much at all…

THe yii blog demo without op code cache consumes 17mb, and with about 3mb.

thanks, Dckurushin

they say php is a stateless language,that is, for every new request, php would have to load required components, parse the scripts, connect the database etc all over again. thus php is actually slower than other language, e.g Java.

i don’t know if Yii has any special mechanism to overcome some of php’s shortcomings.

You need eaccelerator , xcache apc or zend optimizer etc.