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 dispat
For Minify css and Js in cakephp 2 you can use one of the plugin
https://github.com/Er-Kalpesh/CakePHP-Combinator-Plugin
which is best for optimization of css and js.
Some further good tips here including using a modified router::url
helper for performance as well as some common sense:
http://www.chainfire.eu/articles/76/CakePHP_and_performance_for_noobs_/
I think this is a really good question. Here are a couple things I do to speed up cake apps.
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
In apache, move the code from your .htaccess
into the main server config/vhost/whatever and set AllowOverride None
.
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/
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
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]
I just wrote about some more tips to drastically speed up cakephp apps with some practical code attached: http://www.dereuromark.de/2012/02/13/what-really-speeds-up-your-cakephp-app/
Both for CakePHP and other things, just get a more powerful server, more GHz and RAM. Prices get cheaper every year. Although if you are on a VPS, I understand things can be tight.
And sometimes new hardware is cheaper than paying for someone to optimise the code...
For CakePHP 2.x the performance bottleneck can be usage of Hash::
functions (https://book.cakephp.org/2.0/en/core-utility-libraries/hash.html).
They're very slow when using complex expressions. It results in better performance if you write this logic by yourself.