呵呵~~这种技术在大型网站的应用其实是很广泛的~~只是没有使用统一的产品~~比如我们新华的首页吧`~实际是每天0点使用一个程序(呵呵~~商业机密了~~)将动态的index_d.php解析一次,生成一个静态的index.php,实际里面全是html代码。这样可以大大降低服务器的负载,因为毕竟有很多人只是看看首页的,在首页里如果有太多的与服务器的交互那不就惨啦`~:)

解决方案 »

  1.   

    同时写数据库和HTML不就得了,没什么太高深的。
      

  2.   

    其实每次发生数据库更新时就重新编译一次静态的代码就行了,zxyufan好像把问题搞复杂了:)
      

  3.   

    新浪、sohu的新闻不可能半天才更新吧?
      

  4.   

    是不是JSP就不存在这个问题?不是说只编译一次吗?
      

  5.   

    怎么编译出一个静态页啊?怎么获得生成的html代码呢?我现在正好需要这个技术,请各位大哥帮忙啊~~~~
      

  6.   

    用ob_start函数将输出重定向到文件不就得了,用的着搞得那么神秘吗?!~··商业机密¥%¥……%
      

  7.   

    那位高手帮忙一下啊?
    回复人: sillyfox(傻狐狸) (2002-1-23 21:04:54)  得0分 
    还有个问题,如何防止生成静态页时两个用户同时写静态文件或在写文件的同时有用户读生成的静态页??请大家一定要帮忙啊~~~~  
      

  8.   

    多线程问题。
    很好解决啊
    就是在数据库那一层产生一个死锁(update)
      

  9.   

    比如:现在有一个人在写了,但还没有写完(这时数据库会给他一个权限date)
    同时:另一个人也想写,但是有人正在写,那么你就把这个想写的人一个死锁(update)直到那个人写完了在把这个权限给这个现在被你(update)的人。
      

  10.   

    to u9lasojow8
    请里不要给我发垃圾邮件!!!!!!!!!!!垃圾
      

  11.   

    一段代码 参考参考
    <?php 
    //这是一个简单的缓存例子: 
    //在本页面中需要随即从几个表中抽取N条记录显示, 因为对数据库操作频繁, 
    //所以采用缓存方法, 24小时内保持不变, 超过则重新生成. 
    //本例子还借用了模板的功能来生成页面. 
    //本文有两种随即产生记录的方法, 分别适应索引Id连续和不连续两种情况, 
    //仅供参考, 具体情况请具体分析. 
    //[email protected] //缓存文件名: 
    $cache_file = 'index.inc'; if (time()-filemtime($cache_file) < 3600*24){ 
        //如果缓存文件的修改时间没超过24小时 
        include ($cache_file); 
        exit; 
    } //home page of learn 
    require "../lib/template.php"; 
    require "../lib/common.php"; 
    require "../lib/config.php"; 
    //require "common.php"; 
    //require "config.php"; $IllnessCount = 5; 
    $AssayCount = 5; 
    $RadiologyCount =5; $IllnessList = &get_rand_field('Illness','Name',$IllnessCount); 
    $AssayList = &get_rand_field('Assay','Name',$AssayCount); 
    $RadiologyList = &get_rand_field('Radiology','Name',$RadiologyCount); 
    function &get_rand_field($table,$field,$n){ 
    //$table is identified by Id 
        $q = "select count(*) from $table"; 
        $total = mysql_result(mysql_query($q),0,0); 
        $n = min($total,$n); //如果数据的主索引按Id连续: 
        $id_list=array(); 
        while (sizeof($id_list)<$n){ 
            mt_srand ((double) microtime() * 1000000);     
            $rand = mt_rand(0,$total-1); 
            if (in_array($rand,$id_list)) 
                continue; 
            $id_list[] = $rand; 
        } 
        $q = "select Id,$field from $table where Id in(".implode($id_list,',').")"; 
        $r = mysql_query($q) or error_die("查询出错"); 
        return $r; /* 如果主索引Id非连续: (中间记录可能被删除过) 
        for ($i=0; $i<$n; $i++){ 
            $id_lists= implode($id_list,','); 
            mt_srand ((double) microtime() * 1000000);     
            $rand = mt_rand(0,$total-1); 
            $q = "select Id,$field from $table "; 
            if ($id_lists != '') 
                $q .= "where Id not in($id_lists) "; 
            $q .= "limit $rand,1"; 
            $r = mysql_query($q) or error_die("查询出错"); 
            $id_list[] = mysql_result($r,0,0); 
            mysql_data_seek($r,0); 
            $r_list[] = mysql_fetch_object($r); 
            $total--; 
        } 
        return $r_list; 
    */ 
    } //output to html 
    $t = new Template(".", "keep"); 
    $t->set_file(array("page" => "index.ihtml")); $t->set_var(array( 
        "EmptyBlock" => " " 
        )); $t->set_block("page", "Loop_Illness", "a"); 
    foreach($IllnessList as $row) { 
        $t->set_var(array( 
            "RandIllness" => html_echo($row->Name), 
            "IllnessId" => $row->Id, 
            )); 
        $t->parse("a", "Loop_Illness", true); 

    if (sizeof($IllnessList)==0) 
        $t->parse("a", "EmptyBlock", true); $t->set_block("page", "Loop_Assay", "loop_assay"); 
    foreach($AssayList as $row) { 
        $t->set_var(array( 
            "RandAssay" => html_echo($row->Name), 
            "AssayId" => $row->Id, 
            )); 
        $t->parse("loop_assay", "Loop_Assay", true); 

    if (sizeof($AssayList)==0) 
        $t->parse("loop_assay", "EmptyBlock", true); $t->set_block("page", "Loop_Radiology", "loop_radiology"); 
    foreach($RadiologyList as $row) { 
        $t->set_var(array( 
            "RandRadiology" => html_echo($row->Name), 
            "RadiologyId" => $row->Id, 
            )); 
        $t->parse("loop_radiology", "Loop_Radiology", true); 

    if (sizeof($RadiologyList)==0) 
        $t->parse("loop_radiology", "EmptyBlock", true); //输出新生成的页面 
    $t->pparse("out", array("page")); //保存缓冲页面 
    $fp = fopen($cache_file,'w'); 
    fputs($fp,$t->subst("out")); 
    fclose($fp); 
    ?>
      

  12.   

    void ob_start(void); 
    此函数告诉 PHP 处理器把所有输出重定向到内部缓冲,调用这个函数后,就不会有输出到浏览器。 
      

  13.   

    PHP4 采用了缓冲机制,在你决定发送以前,所有内容只是存在于缓冲中,而不是直接发送给浏览器,虽然你可以用 header 和 setcookie 函数来实现,但是这两个函数相比于功能强大的输出函数来说只是一点“雕虫小技”。
      

  14.   

    to: cknuke(龙天) 
    程序编的蛮专业的嘛
    想法不错
      

  15.   

    http://www.csdn.net/Expert/topic/502/502836.shtm
      

  16.   

    ob_get_contents()
    不能用怎么回事情??急啊~~~~救命