How to cache dynamic PHP page

Viewed 42789

How to cache PHP page which has mysql query. Any example will be great and helpful.

5 Answers

The important thing, often overlooked when there is discussion about caching, is process synchronization to avoid thread race (see: https://en.wikipedia.org/wiki/Race_condition).

Typical caching scenario in PHP without synchronization looks like this: if you don't have resource in the cache, or resource is expired, it must be created and put into cache. First thread/process that happens to encounter such condition is trying to create resource, and during that time, other threads will also create the resource, which leads to thread race, cache slamming and performance downspike.

Problem is magnified by number of concurrent threads and workload created by resource creation task. On busy systems it may lead to serious problems.

There is very few caching systems for PHP that takes it into consideration synchronization.

One of them is php-no-slam-cache: https://github.com/tztztztz/php-no-slam-cache

Related