MEMQ : Fast queue implementation using Memcached and PHP only

Posted 22 CommentsPosted in PHP, Scalability
Memcached is a scalable caching solution developed by Danga interactive. One can do a lot of cool things using memcached including spam control, online-offline detection of users, building scalable web services. In this post, I will demonstrate and explain how to implement fast scalable queues in PHP. MEMQ: Overview Every queue is uniquely identified by it's name. Let's consider a queue named "foo" and see how MEMQ will implement it inside memcached: Two keys namely, foo_head and foo_tail contains meta information about the queue While queuing, item is saved in key foo_1234, where 1234 is the current value of key...

WordPress style “Duplicate comment detection” using Memcached and PHP

Posted 9 CommentsPosted in Scalability
If you have a knack of leaving comments on blogs, chances are you might have experienced a wordpress error page saying "Duplicate comment detected; it looks as though you’ve already said that!", probably because you were not sure that your comment was saved last time and you tried to re-post your comment. In this blog post, I will put up some sample PHP code for Duplicate comment detection using Memcached without touching the databases. Towards the end, I will also discuss how the script can be modified for usage in any environment including forums and social networking websites. Duplicate comment...

How to use locks for assuring atomic operation in Memcached?

Posted 12 CommentsPosted in Scalability
Memcached provide atomic increment and decrement commands to manipulate integer (key,value) pairs. However special care should be taken to ensure application performance and possible race conditions while using memcached. In this blog post, I will first build a facebook style "like" application using atomic increment command of memcached. Also, I will discuss various technical difficulty one would face while ensuring atomicity in this application. Finally, I will demo how to ensure atomicity over a requested process using custom locks in memcached. Where should I care about it? Lets consider a sample application as depicted by the flow diagram below: The...

Introducing MemChat: Open source group chat framework in PHP supporting Memcached, APC, SQLite, Flat Files and MySQL

Posted 33 CommentsPosted in Open Source
MemChat is an open source group chat framework for personal and enterprise level websites. Written in PHP, MemChat can be configured to run with Memcached, APC, SQLite, Flat files and MySQL as it's storage engine. With memcached, APC and Flat files serving as temporary storages and MySQL, SQLites being permanent storage engines. MemChat uses MemBurger API for storing all the incoming messages in the storage engine. MemBurger is an open source PHP wrapper for all the storage engines mentioned above providing Collapsed Forwarding and Stale-While-Revalidate functionality. MemChat can also be configured to notify the site owners at various event handlers...

Memcached and “N” things you can do with it – Part 1

Posted 19 CommentsPosted in PHP, Scalability
In my last post, MySQL Query Cache, WP-Cache, APC, Memcache - What to choose, I discussed in brief about 4 caching technologies which you might have used knowingly or unknowingly. Towards the end, we came to the conclusion that Memcached is the best caching solution when you are looking for speed and number of hits per second. By my experience, Memcached is capable of handling more than 100 Million PV's per month without any problem. However, towards the end, I did also discuss why memcached is unreliable and insecure. In this post, I will dig a level deeper into memcached....

MySQL Query Cache, WP-Cache, APC, Memcache – What to choose

Posted 44 CommentsPosted in PHP, Scalability
Hello Cache Freaks, Ever since I changed my job (from Business Intelligence to Web development) and started working with my present employer, I have had a chance to work on a lot of scalable projects. From making my project to scale from 20 Million PV's to 100 Million PV's to development of an internal tool, the answer to all scalable applications have been caching. There are a lot of caching techniques which are being employed by sites worldwide. WP-Cache used in wordpress - a file system based caching mechanismAPC Cache - an opcode based caching systemMemcache - an in memory...