开发者

How to optimize cakephp and SQL web based applications?

开发者 https://www.devze.com 2023-03-04 14:48 出处:网络
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 star

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:

  1. Serve static content independent from cake from a cookieless domain.

  2. Avoid starting a session whenever this is not necessary.

  3. Avoid loading helpers and components when not used.

  4. Minify all your JS and CSS and deliver them from a single file.

  5. Use caching whenever possible (elements, queries, views).

  6. Use requestAction with caution and always with cache.

  7. 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.

  8. 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)

  9. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号