Using cache in php script

安稳与你 提交于 2019-12-02 05:06:45

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/11355409/using-cache-in-php-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!