4 ms·
Getting Web Scale with PHP & Memcached
- Udo 16y agoPretty basic article, but yes, Memcache is awesome. With a PHP/Memcache/Nginx stack I was able to make a massive traffic site work on the smallest-possible EC2 server. But there are two things that are even more important when running PHP: a good FastCGI server (such as PHP-FPM) and an opcode cache like APC. Without those two, the PHP CGI execution model would be pure insanity; not only would it restart the entire process for each request, it would also recompile every file. I think it's sad that those measures are not standard in every PHP environment, but then again they're not particularly difficult to configure...
- Mikushi 16y agoSums it up pretty good. Only thing is, memcached is kinda outdated, it's not safe, can put very easily your environment at risk in case of crash. For anybody starting to wander in the world of caching with PHP, i'd recommend Redis, much better, safer and on an other planet when it comes to features available.
- Udo 16y agoYou're right that memcached does not have security features (though I believe they added basic authentication). In fact, it couldn't be any simpler in its design, it really has only one feature at all when it comes right down to it. This limits its usage, but its simplicity is also a big strength as long as programmers and sysadmins don't lose sight of its purpose. I have not used Redis (yet), but from what I understand it really solves a different problem. It's a key-value store. Though Memcached data is also accessed by keys, it is not a store, it's a very fast cache with minimal overhead.
- Mikushi 16y agoRedis solves the same problem, while offering way more features. In terms of speed, Redis is in the same area. Memcached is also a key-value store (quote from the official site "Memcached is an in-memory key-value store for small chunks of arbitrary data"). I've been slowly using Redis more and more over the past 6 months, and as an heavy memcached user, i can tell you that i don't really see a need for both, might as well take advantage of the useful features Redis as to offer on top of the "basic" Memcached-like stuff.
- Udo 16y agoRedis is persistent, replicated storage, isn't it? No matter what buzzwords they use on their site, Memcached is a volatile cache, it should never be used to store otherwise irretrievable information. I know, people use it for stuff like session storage, but that's really not a good use case for it. I don't want to attack Redis, so there is no need to defend it. Maybe memcached-like behavior is one of its many features, but I personally like Memcached exactly because of its simplicity.
- loire280 16y agoSince Redis keeps the dataset in RAM, it offers performance in the same class as memcached -- though memcached is significantly faster. There's probably a way to run it without the persistence (or just decrease the snapshot frequency), though you could just set it up to clear the tables when the application restarts and not worry about it. If you're looking for a more "modern" replacement, it's a good choice.
- Udo 16y agoThank you for clearing that up. Because I never used Redis before I wasn't sure, but my impression was also that it is intended for persistent storage and that there is a difference between a cache and a storage engine.
- terryjsmith 16y agoThe term "web scale" needs to go away; it just doesn't make sense. No one site will ever need to be "web scale" by its definition since it's highly unlikely one site will get all of the web's traffic. The term could only apply to a crawler or something similar that actually consumes the whole web. Your website will either scale or it won't and there are various levels of magnitude, but the term "web scale" is confusing and buzzwordy.
- yuvadam 16y agoCaching 101.
- deleted 16y ago[deleted]
- deleted 16y ago[deleted]
- methodin 16y agoTo anyone else that might start with Memcache it should be noted that it does not fail gracefully if your servers decide to crap out. We deployed a group of 8 Memcache servers to our production environment and due to a mis-configuration all the webservers were brought to their knees since the get/set would wait for the Memcache server to respond even with the PHP specific settings (timeout etc..) set to appropriate values. For a safe use you should implement a simple home-grown "active memcache server" list so in the event of utter failure only the first couple requests to Memcache will try to request from the server list and as they fail you can knock them out of the pool. It's worth the 10 minutes it takes to implement and will save your ass if things go wrong.