Recently I am dealing with bad performance in an php application that I have build,
googling this issue I found out that using services like memcached you can archive a huge performance improvements.

The weird thing comes when I try to find a very good and detailed example I failed to find something.
Could someone helps me giving a good url or example using php + mysql + memcached?!

Thank you!

Recommended Answers

All 3 Replies


We use both memcached and redis, which are both key-value storage. We use them to cache data that is significantly more expensive to retrieve from the database. Basically the logic would be something like this:

Attempt to retrieve data from cache
If data exists in cache:
    Show it
If data does not exist in cache:
    Retrieve it from the database
    Save it to the cache
    Show it

Dani thank you for your reply.
I understand the theory how it works, but I wanted a detailed example.

There are a lot of information in google and a lot of methods to improve the performace
of you code and I am getting very confused. Even now to told me something new memcached + redis :O

If you can plz post here a full example how can this be done!
Thank you.

There are so many infinite use cases that it's not really possible to post an example without a little bit of guidance. For example, if you post your code of a big database query that you are pulling, and tell me that this query is very resource intensive and your u would like to cache the results, then I can help you write the code for that. But you need to be a little more detailed in your request :)

Both memcache and redid are key/value stores, but the difference is that Redis is persistent while memcache is not. That means that while both store in ram, redis additionally writes to eh hard drive. Therefore, data can be set to exist infinitely. Memcache, meanwhile, is just for caching data that exists elsewhere in a permanent data storage.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.