定时?php 如何定时?用c++ 做吧...........
解决方案 »
- 已知一个php的文件,如何知道这个文件里面是否含有类,类名是什么?
- 关于时间段模糊查询
- php 刚开始自学 请前辈一定帮忙。
- 排序问题的数据库设计
- 被Rs.recordcount=-1 折磨死了
- 谁能看懂这个代码怎么形成的
- ========= 如何用PHP 列出 MSSQL 2000 数据库里的表 =======
- session_register('varname')??????
- 在删除记录时如何作弹出提示窗口,请高人指点!
- 请问网页中 cfm是用什么语言写的?对应的操作系统和数据库又是什么?
- 请教我做二次开发,修改其中一个php文件,修改后报错,说不能修改该文件??
- SELECT 查询效率太低的问题!
在一个用户经常访问的页面内加一个判断,第一次,将更新日期写入数据库(比如时戳为a),这样用户每次访问该页面时都检测一次,比较当前时戳(b),如果b和a的时间差值为3天,则重新生成一次HTML,同时更新数据库中时戳,反之跳过。
这样不就间接地实现了吗
/*
Class : Lcache
Author : L0ading <[email protected]>
2004.04.03Usage :
$sample = new Lcache();
echo "hello";
$sample->out();
*/class Lcache {
var $bufferFileName;
var $en;
var $content; function Lcache($LimitTime="600") {
$this->bufferFileName = basename($_SERVER['PHP_SELF'],".php").".buf";
ob_start(); if (!file_exists($this->bufferFileName) || (int)date(time()-@filemtime($this->bufferFileName))>$LimitTime) {
$this->en = true;
} else {
$this->en = false;
$this->readBuf();
}
} function readBuf() {
$fp = fopen($this->bufferFileName,"r");
$this->content = fread($fp,filesize($this->bufferFileName));
} function get() {
$this->content = ob_get_contents();
ob_clean();
} function bufferTo() {
$fp = fopen($this->bufferFileName,"w");
fputs($fp,$this->content);
fclose($fp);
} function out() {
$this->get();
if ($this->en) {
$this->bufferTo();
}
echo $this->content;
}
}?>
例如半个小时刷新一次 crontab 里面就是 0,30 * * * * /root/getindex
(crontabe 具体用法请看 man手册)注意是 -O 不是-0
写然后保存为js文件
可以定期查询数据库获得最新的文章信息后直接修改js文件
phanx(饭扫光)的办法也很好.
hahawen(变态的大龄青年)的方法对服务器有一定开销,不是很好.以前我们做新闻系统的时候就是这么做.我的方法和老高的差不多:<?php
error_reporting(E_ALL & ~E_NOTICE);
/////////////////////////////////////////////////////
//*********判断缓存中的文件是否过期****************//
//***$fn:文件名***$expire:时间间隔数**************//
////////////////////////////////////////////////////
function isTimeOut($fn,$expire){
$tag = 1;
if (is_file($fn)){
$ftime = filemtime($fn);//文件创建时间
$ctime = time(); //当前时间
if ($ctime - $ftime < $expire){
$tag = 0;
}
}
return $tag;
}$filename = 'index.html';
//如果文件没有过期则读取缓存中的内容
if (!isTimeOut($filename,60)){
readfile($filename);
exit;
}
//否则使用缓存输出文件
else{
ob_start();
include('createIndex.php'); //创建index.html
$content=ob_get_contents(); //得到缓冲区的内容
$fp=fopen($filename,'w'); //打开文件
fwrite($fp,$content); //写入信息
fclose($fp); //关闭文件
}
?>
http://xgb.newgxu.cn/test2.php另外,欢迎csdn友发表别的看法...大家互相学习嘛.......嘻嘻...