定时?php 如何定时?用c++ 做吧...........

解决方案 »

  1.   

    可以做一个定时更新的假象,例如我们想每三天更新一次:
    在一个用户经常访问的页面内加一个判断,第一次,将更新日期写入数据库(比如时戳为a),这样用户每次访问该页面时都检测一次,比较当前时戳(b),如果b和a的时间差值为3天,则重新生成一次HTML,同时更新数据库中时戳,反之跳过。
    这样不就间接地实现了吗
      

  2.   

    <?php
    /*
    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;
    }
    }?>
      

  3.   

    如果不要将大量的页面转为静态,而只是针对部分页面,例如首页的话。那么在linux下面的一个好办法如下:编辑一个文件例如 getindex ,内容为用 wget -O /path/to/your/dir/index.html  http://www.your.com/yyyyy_for_index.php然后再crontab里面设定运行 就ok了
    例如半个小时刷新一次 crontab 里面就是  0,30 * * * *    /root/getindex
    (crontabe 具体用法请看 man手册)注意是 -O 不是-0
      

  4.   

    为了减轻服务器的负担,可以把经常需要更换的页面用javascript中document.write
    写然后保存为js文件
    可以定期查询数据库获得最新的文章信息后直接修改js文件
      

  5.   

    gaofaq(老高)的做法不错,
      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);                //关闭文件 
    }
    ?>
      

  6.   

    我在学校的服务器上放了一个测试页,大家不妨去试试看...
    http://xgb.newgxu.cn/test2.php另外,欢迎csdn友发表别的看法...大家互相学习嘛.......嘻嘻...