PHP Simple File Caching Tutorial

Caching is the practice of storing data in and retrieving data from a file, database or memory so that future requests for that data can be served faster. The data stored in a cache might be the result of an earlier computation or duplicate of data. Memory is faster to access than a file, a remote URL, a database or any other external store of information. Besides that, caching is temporarily storing recently used information such as content, which includes HTML pages, images, files and Web objects to make it faster for the user to access it, which helps improve the efficiency of the computer and its overall performance. In this tutorial, I will cover on how to implements PHP simple file caching in your web page.

Add a new project

Start your PHP editor and web server, you can go to download PHPStorm and XMPP. Then open your PHP editor create a new project “php-cache-filing”.

Create a new folder

Right-click the package name and create a new folder “cache”. This folder is to create a cache file after load the web page.

Create a new PHP file

After creating a project, right click your project name and create a new PHP file “example”. The following source code is the sample implementation of caching the file. After load the web page, it will generate a cache file in your cache folder. If the cache folder existing file, it will load from the existing file.

Run your project

Now, you can run example.php in your browser. It will load a web page, if web page cache not exists, it will generate a new cache file.

Note : you can check the loading speed in the bottom of the page to compare with file caching aprroach.

(PHP Simple File Caching)

Source Code

 

 

(Visited 151 times, 1 visits today)
Advertisements

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

GET YOUR EBOOK FOR FREE

Unlock free ebook "Beginning Programming ALL-IN-ONE Desk Reference for DUMMIES" now!

We will send a copy to your email