Alternative PHP Cache (APC)

One of our customer product generates embeddable widgets, which its users can embed in their websites. Once of the critical requirement was to keep track of views of every embedded widget, in every web page. The view count was tracked using a web service call, back to server, from the widget, every time it was viewed. As these widgets started becoming viral, and being re-embedded in several web pages, the load on database went on increasing, since it was triggering few hundreds of updates/ inserts per second. This scenario was impacting the performance of database, and hence the system. There was a need to batch these database updates.

How did we handle this?

Since we had tolerance for delay of 5-10 minutes before the number of views actually updated on widget, we decided to cache the updated in memory for @ 5 – 10 minutes, aggregate the counts in the same, and then finally update the aggregated view count in the database, once in 5-10 minutes. After evaluating several options, we decided to use Alternate PHP cache (APC).

The Alternative PHP Cache (APC) is a free and open opcode cache for PHP that provides a robust framework for caching and optimizing PHP intermediate code. We used it to store number of chart views per widget, updated/ incremented the count with every new count, and then updated it finally in db every 5- 10 minutes. This tremendously reduced the load on database, and hence the application, and has been robust for heavy loads.

Tushar Shinde is a Lead Developer at Compassites Software. He has more than six years of work experience in web-based systems, content management tools, database design and computer programming. He holds a Bachelor of Information Technology degree from Pune University, India.