PHP Simple Cache

Buy from CodeCanyon


PHP Simple Cache lets you create cache for any PHP website quickly and easily. Use this script to speed up your website.

Live Example - Current Cached Pages

No page in cache

PHP Simple Cache Features


PHP is a programming language to create dynamic websites. Dynamic websites display content that is requested by user. This content changes if user submits form, logs in, sends email, submits comment, add/retrieve data in/from database etc. PHP scripts also retrieve data from database and display it on a dynamic page. Every time such page is loaded in browser, PHP server has to translate PHP script, request database server, retrieve data and then display it for user.

Cache reduces server's effort. Cache stores a translated version of page (HTML) to display it later. When this page is called again, cache verifies its cached version. If cached copy of page is available and is not expired, it will be displayed and PHP server won't have to translate PHP scripts and connect to database server to retrieve data. This process reduces server memory usage, server effort snd server resources consumption.

If some kind of dynamic action is performed, old cache is deleted and a new fresh cached copy of page is created for later use. In this way, you website remains up and running at fast speed. A cached version of page is much faster than original dynamic page.

It is logical and based on rule that "Only go through PHP scripts and database if content of page changes. If content is same, store its copy, do not go through PHP scripts and database tables and display cached copy."

PHP Simple Cache is a small PHP accelerator that substantially increases the speed of PHP website and improves the web page generation process by server. Basically it cahces a page that has been loaded in browser once. Next time cached HTML version of PHP page loads instead of telling PHP server to translate the PHP code again. Similarly, in case of data retrival from database server, it will cache that data and store it in cached file to display it later, instead of connecting to database again.

It enables dynamic PHP pages to load quickly and reduces server load by saving server translated page into cached files and serving that saved data on demand.


Include this script (cache.php) at the top of every page in your website that you want to be cached and that's it. If not every page, you can also include this script in database file, configuration file or settings file of your project to cache whole website. Turn off cache for individual pages by passing a single variable to the page you do not want to be cached. If passing a variable or submitting a form, include another single script file to empty cache, so that dynamic functionality of website remains intact.

In short, cache all PHP website, but when performaing a dynamic action on any individual page, refresh cache to ensure site's stable functionality and optimal performance at the same time. See docs for implementation guidance.

Use Cache

Grab cache.php file, open it in editor, adjust 'cache folder' settings (name and location), adjust cache time and include cache.php in website. That's it. By default settings, you need to create siteCache folder at root of your website. Place cache.php file in root of website and you are good to go after including cache.php file in your project, like below:

//.. rest of page code ..//
Turn Cache Off for Individual Page
//.. rest of page code ..//
//.. rest of page code ..//
Delete Cache

If you perform any dynamic task/action at website, or session data changes, or user logs in etc. you will need to delete cache to see changes or updates.

Cache Folder Path

Its defined in cache.php file. Change siteCache according to your need.

// absolute path - recommended
define('CACHE_PATH', $_SERVER["DOCUMENT_ROOT"]."/siteCache/");
// while $_SERVER["DOCUMENT_ROOT"] is your root directory path at your web host .. e.g.
// If your project and the cache folder are not at the root path of server, e.g.
// Then cache folder path will be like below
// define('CACHE_PATH', $_SERVER["DOCUMENT_ROOT"]."/project/siteCache/");
// relative path - not recommended
define('CACHE_PATH', "siteCache/");

© 2013 TechMynd