请教PHP有什么好的缓存吗
请问PHP有什么好的缓存吗
比如我要缓存index.php首页,10分钟更新一次,怎么写缓存啊!
以前做.net,现在转PHP,很多页面需要缓存,不知道php怎么写
求写法,最好有个demo
比如index.php,然后别人访问的时候每10分钟更新1次index.html,当然index.html是index.php的缓存,
及时不生成index.html,
要求index.php每5分钟更新1次数据
怎么写啊!!!
生成最好!!
------解决方案--------------------
用smarty模板哇,里面有缓存,http://www.smarty.net/docsv2/en/,手册内容好像有点多,google一下.
------解决方案--------------------
全英文的
------解决方案--------------------
memcached
------解决方案--------------------
你在.net怎么做,就在php怎么做
不过是方言不同而已
------解决方案--------------------
memcached缓存页面?没做过,是把整个页面丢进一个值里面么?
------解决方案--------------------
在这个场景下memcached做缓存是很2的事情。不提通讯量,你一个生成好的纯静态页,每次还要先加载php,从memcached服务器读取出来,再返回给客户机,效率很低。
推荐的方法是把index.html生成文件缓存,然后跑脚本定时更新。
------解决方案--------------------
你要缓存首先要知道自己为什么要缓存,想缓存什么...
楼上的每个回答都是在某种程度上可行的, 关键看你要做啥...
------解决方案--------------------
要缓存整个页面的话,直接自己创建个静态文件就可以了。ob_start(),ob_get_contents(),flush()或ob_flush(),这四个函数足够了。
每次请求这个页面时判断一下,如果这个静态文件存在,或者当前时间-它的创建时间>=10分钟,就重新用上面的方法生成静态页面。否则就直接读出这个静态文件返回给浏览器。
------解决方案--------------------
memcached或redis适合缓存数据,这种需要缓存整个页面的,用上面的方法最好。
------解决方案--------------------
couch db
------解决方案--------------------
谢谢大家帮忙,俺测试了1个页面缓存,生成1个html,关键并不是我所需要的,
比如根据条件我查询数据,缓存时间设置1分钟,
结果我选择查询条件,数据没发生改变
我想需要的是选择查询时间,数据发生改变,同事,同样的查询条件,1分钟更新一次,
比如我选择时间区域,开始默认是近1天数据,
当我选择前天条件查询的时候,要的是前天的诗句,
如果我再次查询前天数据,还是前天数据,但1分钟内不会有更新,1分钟后查询才会有更新,
1分钟内当我选择后天数据,是后天数据,而不是前天的数据
就是查询条件改变,根据当天条件进行1分钟或者1小时,1天的缓存,
不影响其他条件查询,当然其他条件也是1分钟或者1小时。1天的时间缓存
------解决方案--------------------
说白了,就是根据条件查询,进行数据缓存
------解决方案--------------------
按你#11描述,你的设想是有问题的
这样的话,你需要缓存的是自有史以来所有时刻的现场。因为任何人都可能从以往的任何时刻开始查询
以一分钟为界一年为期,至少也需要6151680个缓存项目
这显然是不可取的
由于可用的查询表达式是有限的,所以你可以依据查询表达式创建若干个视图。从而使查询运算交与数据库后台完成
------解决方案--------------------
是啊!所以头疼啊!!!
所以想放到内存中,然后定期清理内存
------解决方案--------------------
用输入输出缓冲做个文件缓存
------解决方案--------------------
新手,路过~你这个需求我觉得用静态页缓存比较好
------解决方案--------------------
这个和一些网址导航类网站的首页缓存是一样的。只不过他们将首页缓存在客户端的期限可能长一点,比如1个月、3个月......
具体方法为:
1、将首页所引用的相关素件(图片、CSS文件、JS文件等)存到一个专门的目录中,比如cache;
2、.htaccess中加入规则:
#缓存首页物件
#RewriteCond %{HTTP_HOST} ^www.162100.com [NC]
#RewriteCond %{REQUEST_URI} ^$ [OR]
#RewriteCond %{REQUEST_URI} ^/$ [OR]
#RewriteCond %{REQUEST_URI} ^/index.html$ [NC]
#RewriteRule (index\.html) gzip.php?cfile=$1 [L]
#RewriteRule ^(cache\/.+)$ gzip.php?cfile=$1 [L]
3、根目录(即同index.html一个目录)做一个文件gzip.php,代码为:
<?php <div class="clear">

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip
