Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been a keen fan and user of CakePHP for about 2.5 years now, but the main bugbear that most fellow developers level at the framework is that it's slow, and the dispatch cycle takes too long to make it a viable solution for production environments.

I'm hoping that this question will inspire people to share their tips, tricks and hacks for speeding up CakePHP performance.

The blog post I most often refer to is pseudocoder's 8 Ways to Speed Up the Performance of CakePHP Apps, which has great tips, but there must be more out there!

So please feel free to share your thoughts on making this excellent framework that much more nimble!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
580 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think this is a really good question. Here are a couple things I do to speed up cake apps.

  1. As mentioned in the comments of the linked article, cutting down on the $uses array helps a little. You can access associated models by going through their associationg. So if City and Address where associated, you could access address by $this->City->Address instead of including both in the $uses array

  2. In apache, move the code from your .htaccess into the main server config/vhost/whatever and set AllowOverride None.

  3. In a load balanced environment, move sessions from the DB to memcache. Memcache is easy as hell to setup, and the cake's DB session class leaves much to be desired. In high load application the garbage collection will kill you, as it ends up running every second or so. Also, here's a great little script that gives you stats about your memcache usage (based of apc.php) http://livebookmark.net/journal/2008/05/21/memcachephp-stats-like-apcphp/

  4. As Mark Story mentions in the comments section of the 8 ways article, compressing your assets is a very good idea. Here is a good script that minifies both js and css files, which can be used to replace the default css.php that comes bundled with cake. http://www.milesj.me/blog/read/32/CSSJSAsset-Compression-In-CakePHP

  5. If for some reason people hit alot of images/css/js that don't exist anymore, it might be beneficial to make sure those pages do not generate a cake 404 error, as it has to go through the whole cake dispatching process, generates a session etc. It's as simple as changing this:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
    

    to this:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/(img|css|js)/(.*)$
    RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

Just Browsing Browsing

[2] html - How to create even cell spacing within a

548k questions

547k answers

4 comments

86.3k users

...