$psql=$empire->query("SELECT newstime,titleurl,classid,filename,newspath,id,groupid FROM {$dbtbpre}ecms_".$tbname." WHERE ".$where." AND checked=1 ORDER BY newstime DESC");   $flag=1;
$smaps="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n";//sub
while($q=$empire->fetch($psql))
        {
          $titleurl=sys_ReturnBqTitleLink($q);
          $smaps.="<url>\r\n<loc>".$titleurl."</loc>\r\n<priority>0.5</priority>\r\n<lastmod>".date('Y-m-d',$q[newstime])."</lastmod>\r\n</url>\r\n";
  if($flag==1){$sitemap.="<lastmod>".date('Y-m-d',$q[newstime])."</lastmod>\r\n</sitemap>\r\n";}
  $flag++;
        }
$smaps.="</urlset>";
file_put_contents('../../xml/'.$xmlname.'', $smaps);
比如像上面这样的,假如表的数据很大,那么怎么样才能减轻服务器的负担?我看那些备份和恢复数据的都有2秒后继续的缓冲,应该怎么弄?

解决方案 »

  1.   

    http://willko.javaeye.com/blog/325618看一下,分页处理。
      

  2.   

    newstime这个是date吧,orderby date理论上很慢的而且一次把所有的数据都拿出来如果不能分页就考虑从数据库那优化吧,可以考虑把date转换成long型的,加个index查询就会一下子快很多
      

  3.   

    $psql=$empire->query("SELECT newstime,titleurl,classid,filename,newspath,id,groupid FROM {$dbtbpre}ecms_".$tbname." WHERE ".$where." AND checked=1 ORDER BY newstime DESC limit
     $startnum , $perpage
     ");用 limit
      

  4.   

    cache:
    if (file_exists('../../xml/cache.dat') && time() - filemtime('../../xml/cache.dat') < 86400)
    {
    $xml = file_get_contents('../../xml/cache.dat');
    }
    else
    {
            $xml=..........//此处为程序生成xml段         file_put_contents('../../xml/cache.dat', $xml);}