在PHP脚本中使用缓存 [英] Using cache in php script

查看:82
本文介绍了在PHP脚本中使用缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对php中的缓存感到困惑.我在php文件中创建了一个要显示2到500的文件.现在,我想使用缓存文件来存储数据并显示它.我的代码在下面.

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 />";
?>

现在如何使用缓存文件保存输出并在浏览器中进一步显示.如果还有其他方法可以在php中使用缓存文件,请帮助我.在php文件中,我想了解有关节省时间的信息.如何使用php中的缓存脚本节省时间来存储输出并进一步显示.

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.

推荐答案

PHP内部有几种缓存形式.

There are several forms of caching from within PHP.

如果您可以访问Web主机上的memcached或APC(某些共享计划禁用了此功能),请查找它们,因为它们被认为是相当高性能的缓存形式,因为它直接利用系统内存(memcached更适合用于分布式系统).

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/zh/book.apc.php

如果没有,请查看文件缓存. PHP带有一个方便的文件库(在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

最后,您可能会研究SQL缓存.尽管与其他选项相比通常不建议这样做,但是也可以选择希望通过数据库存储的数据(如果需要将其链接到表中的其他数据).

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

祝你好运!

这篇关于在PHP脚本中使用缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆