Speeding Up Your CakePHP Website using Apache Modules ( 90 )



Probably your CakePHP should run till now under PHP5.5 or at least above 5.0 version.

Override PHP Settings

So, the first thing you can do is to check if zLib is installed and active on your server.
Than you can try to override php init settings if Directory AllowOverride value is set as All.
This means that Master Value remains Off, but Local value has to be On after you write output_compression as 4096 value in your htaccess file.

// [IfModule mod_php5.c]
php_value zlib.output_compression 4096
php_value zlib.output_compression_level -1
php_value zlib.output_handler ob_gzhandler
// [/IfModule]

Additionally you can disable Error reporting and set new values to all max predefined values:

// [IfModule mod_php5.c]
# supress php errors
php_flag display_startup_errors Off
php_flag display_errors Off
php_flag html_errors Off
php_flag magic_quotes_gpc Off
php_flag track_vars Off
php_flag register_globals Off
php_flag log_errors Off

php_value docref_root 0
php_value docref_ext 0
php_value max_execution_time 0

php_value post_max_size 10M
php_value upload_max_filesize 10M
php_value memory_limit 128M
php_value max_execution_time 259200
php_value max_input_time 12500
php_value session.gc_maxlifetime 1200
// [/IfModule]

More info about mod_php5:

Deflate compression settings

This option is doing compression for the content before it's delivered to the client.

// [IfModule mod_deflate.c]
#compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript# Or, compress certain file types by extension:

SetOutputFilter DEFLATE

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
// [/IfModule]

More info about mod_deflate:

Expires settings

Content is fetched from cache until this time has passed.

// [IfModule mod_expires.c]
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 1 month"
// [/IfModule]

More info about mod_expires:

Cache-Control For Headers

// [ifModule mod_headers.c]

Header set Cache-Control "max-age=2592000, public"


Header set Cache-Control "max-age=604800, public"


Header set Cache-Control "max-age=43200, private, must-revalidate"

// [/ifModule]

More info about mod_headers:

Alternative way of using Expiress

Version 1

// [ifModule mod_expires.c]
# Expire headers
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
// [/ifModule]

Version 2

// [IfModule mod_expires.c]
# enable expirations
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/pjpeg "access plus 1 week"
ExpiresByType text/javascript "modification plus 1 week"
ExpiresByType application/javascript "modification plus 1 week"
ExpiresByType text/css "modification plus 1 week"
// [/IfModule]