Micro EC2 instances have about 600mb of RAM, which is not really a whole lot to work with – couple this with a heavy framework such as symfony (which is my preferred framework of choice) and you have an extra layer of complexity every HTTP call.
in order to speed things up, we have a number of options available:
- op code caching (using APC / E-Accelarator)
- memory caching (using memcache)
- reverse HTTP proxy caching (using Varnish)
Op Code Caching
op code caching works by storing the results of a compiled php bytecode in cache, so that subsequent requests will look at the cache and return the compiled result rather than having to revisit the compiler. this can yiel a quick performance win with minimal effort and will be the focus on the article.
Memory Caching
memory caching works like a giant key=>value store in memory where you first check an item exists in the cache, if it does then return it-other get the application to fulfill the request and then store the result in cache, so that subsequent requests will then hit the cache. memory caching takes quite a lot of planning and you have to be very careful on how you are storing things in the cache. So you have a site with multiple clients, you dont want to return other results from the cache from other clients and therefore need to use a unique means of storing things in the cache (such as a client_id or site_id). this is definately overkill for this operation
HTTP Proxy Caching
HTTP Proxy caching is a layer that sits between your web server process (httpd) and the client accessing the site (your web browser) – the cache will be polled first to see if the HTML and related assets are present, and if not then forward the request on to the web server, store the result in the cache and return the request back to the user. subsequent requests will then hit the proxy which depending on the time to live will return the cached result. This approach can yield quick performance boost, buts its something i’ve never tried before and im hesitant on rolling it out for small(ish) projects.
On to the task at hand…
1. start off by ssh’ing to your web root and create a file with the php_info();
$ vi info_check.php
<?php
// check the current php info settings
phpinfo();
?>
2. open up the php page (http://www.mysite.com/info_check.php in your browser and see if APC is installed
3. if not, then carry on (it wasnt on my default install, perhaps you can get a micro instance with APC already installed!)
4. install APC
$ yum install php-apc
5. check the apc config settings are to your taste, check the PECL manual for APC settings
$ vi /etc/php.d/apc.ini
6. restart httpd
$ sudo /etc/init.d/httpd restart
7. check your PHP config page now for APC and it should be there..
Happy Caching!



