Recently I am planning to optimize my web application written on cakephp 1.2.0 framework and MySql db. I optimized it a bit by using memcache and removed the all the models in the $uses array and started using $this->loadModel('SomeModel'); After this my page loading tym is decreased by 200%, but I know there is more scope of optimizing it and will be thankful if any1 co开发者_高级运维uld provide me some tricks, tips or suggestion to do so. Thanks
Some tips:
Serve static content independent from cake from a cookieless domain.
Avoid starting a session whenever this is not necessary.
Avoid loading helpers and components when not used.
Minify all your JS and CSS and deliver them from a single file.
Use caching whenever possible (elements, queries, views).
Use requestAction with caution and always with cache.
Refactor your code into smaller pieces, smaller controllers, smaller views. As a result fine tuning of the above is going to be possible on more places.
Check your code and skip any duplicate calculation/query that could be done once and used multiple times instead (e.g. if you use a localized date format in the views, format it once and re-use it, instead of applying the formatting multiple times on the timestamp)
Dump your Cake's sql log to see what queries in fact run and how long they take. Optimize your query strategy (one big join vs many queries) and data structure (optimal join tables, compare only on indexed fields, avoid the use of any function or transformation in the queries). Remove all unnecessary fields and relationships (e.g. contains).
Use 'recursive' => -1
in you find method whenever you need only current model data without associated models.
精彩评论