PHP: All content tagged as PHP in NoSQL databases and polyglot persistence
A two-part MongoDB tutorial for PHP developers: first part covering installation and the second giving a brief intro to MongoDB PHP API for queries and indexes. While not the tutorial that will get you up and running, it’s still a good resource for beginners.
Original title and link: MongoDB for PHP Developers ( ©myNoSQL)
Derick Rethans’s1 slides are a good MongoDB tutorial for PHP developers covering most of the API.
One brief note about architecture: since it’s impractical to simply query the activity of 500 friends, there are two general approaches for building scalable news feeds:
- Fan-out on read (do these queries ahead of time and cache them)
- Fan-out on-write (write follower-specific copies of every activity so when a given user asks for a feed you can retrieve it in one, simple query)
And why Redis:
First off, why Redis? It’s fast, our data model allows us to store minimal data in each feed entry, and Redis’ data-types are pretty well suited for an activity feed. Lists might seem like an obvious choice and could work for a basic feed implementation, but we ended up using sorted sets for two reasons:
- If you use a timestamp as the score parameter, you can really easily query for feed items based on time
- You can easily get the union of multiple sorted sets in order to generate an aggregated “friend feed”
After looking at all of these I quickly turned to the C extension, Redisent looked nice but did not implement the new unified bulk protocol, and to be true, the code was a bit buggy. The others (Predis, Rediska ) seemed like bloatware, that capture the real essence of PHP (making complicated incoherent APIs) while missing that of Redis (Simple, Fast, Awsomeness).
As you can imagine such a comment generated some reactions and Ori followed up with a (not exactly scientific) benchmark:
While initially considering 6 PHP libraries (phpredis, Predis, Redis PHP bindings (deprecated), Redisent, Rediska), the benchmark didn’t include Rediska as the library is defining a too custom API for Redis.
Do you have a different experiences with any of these Redis PHP libraries?
Besides LAMP, you can now learn about LAP(hp)-CouchDB-:
PHP developers generally use MySQL, but the rise of NoSQL databases has opened up new options for creating web apps. CouchDB’s unique replication feature set and easy API make it a great fit for PHP developers looking to move into a NoSQL database.