I have a confusion about cache in php. I created a file for display 2 to 500 in my php file. Now I want to use the cache file for storing the data and display it. My code is bellow.
<?php
for ($i = 2; $i <= 500; $i++)
echo "The number is:".$i."<br />";
?>
Now how can I use the cache file to save the output and display in the browser further time. If there is some other way to use cache file in php then please help me. In the php file I want to know about the time saving. How to save the time using cache script in php to store the output and display it further.
There are several forms of caching from within PHP.
If you have access to memcached or APC on your webhost (some shared plans disable this functionality), look them up as they are considered fairly high-performance forms of caching as it utilizes the system memory directly (memcached is more suited for distributed systems).
http://php.net/manual/en/book.memcache.php
http://php.net/manual/en/book.apc.php
If not, look into file caching. PHP comes with a handy file library (documented within the PHP documentation) which will allow you to read/write to files.
http://www.php.net/manual/en/ref.filesystem.php
Lastly, you may look into SQL caching. Although this is not typically recommended in comparison to the other options, data that you wish to store through a database may be an option as well (if you need to link it to other data from within your tables).
http://php.net/manual/en/ref.pdo-mysql.php
Good luck!