23 Feb 2010

Making CakePHP websites load quicker

All frameworks are guilty of slowing things down owing to the code overheads and additional processing required to perform even simple tasks. Unfortunately, CakePHP seems to attract more criticism than others in this respect. We're talking milliseconds per page, but it all adds up.

Once a CakePHP website is deployed, there are a number of very basic things to do that should cut that time by more than half. Maybe with extra tweaking, you can get that time down even more.

Anyway, let's start with the key things.

Turn off debugging. Easily overlooked, but in my experience when you disable it, you'll have made the biggest improvement - time now about 50% of original load time.

Add gzip compression to .htaccess:
# compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml


For CakePHP's ./.htaccess (the one at the very root) this will look like:
# compress all text, html, css and javascript:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css

RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

this should be good for another 20% - time now about 30% of original load time.