有偿找人优化个PHP代码
<?php
/**
* 生成Sitemap操作
*
* @version $Id: google_sitemap.php 1 10:00 2011年9月19日Z SSKCN $
* @package SSKCN.Administrator
* @copyright Copyright (c) 2011 - 2013, SSKCN, Inc.
* @license http://www.sskcn.com/license.html
* @link http://www.sskcn.com/
*/
require_once(dirname(__FILE__)."/config.php");
CheckPurview('plus_Sitemap');
require_once(DEDEINC."/typelink.class.php");
$tl = new TypeLink(0);
function DateDiff($interval, $date1, $date2) {
$time_difference = $date2 - $date1;
switch ($interval) {
case "y": $retval = bcdiv($time_difference, 31536000); break;
case "m": $retval = bcdiv($time_difference, 2592000); break;
case "w": $retval = bcdiv($time_difference, 604800); break;
case "d": $retval = bcdiv($time_difference, 86400); break;
case "h": $retval = bcdiv($time_difference, 3600); break;
case "n": $retval = bcdiv($time_difference, 60); break;
case "s": $retval = $time_difference; break;
}
return $retval;
}
function getSonClass($ID) {
$dsql = new DedeSql(false);
$dsql->SetQuery("Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath from `#@__arctype` where reid='".$ID."' and ishidden<>1 order by id,sortrank");
$dsql->execute($ID);
while($row_class = $dsql->getarray($ID)){
ShowMsg($ID);
$SonClass .= "<url>\n";
$iClassUrl = $tl->GetOneTypeUrl($row_class);
$iClassUrl = count(explode("http://",$iClassUrl))>1 ? $iClassUrl: $cfg_basehost.$iClassUrl;
$SonClass .= "<loc>".$iClassUrl."</loc>\n";
$SonClass .= "<lastmod>".date("Y-m-d",time())."T".date("H:i:s+08:00",time())."</lastmod>\n";
$SonClass .= "<changefreq>daily</changefreq>\n";
$SonClass .= "<priority>0.9</priority>\n";
$SonClass .= "</url>\n";
getSonClass($row_class["id"]);
}
return $SonClass;
}
function MK_Dir($path,$pathname){
if(!file_exists($path)){
createDir(dirname($path));
mkdir($path, 0775);
ShowMsg("成功创建目录".$pathname,"javascript:;");
}
}
if(empty($dopost)){
include DEDEADMIN.'/templets/google_sitemap.htm';
}else if($dopost=="make"){
//取得数目
$dsql->SetQuery("Select count(*) as mycount from `#@__archives` where ismake=1");
$dsql->execute();
$row_sum = $dsql->getarray();
if(($sumurl > $row_sum['mycount']) || empty($sumurl)){
$sumurl = $row_sum['mycount'];
}
$pagenum = intval($sumurl/$perpageurl);
$pagenumber = $pagenum;
if($pagenum < ($sumurl/$perpageurl)){
$pagenumber = $pagenum + 1;
}
//创建目录
MK_Dir(dirname(__FILE__)."/../".$filename,$filename);
//索引页sitemap_index.xml
$sitemap_index = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap_index .= "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
for($i=0; $i <= $pagenumber; $i++){
$sitemap_index .= "<sitemap>\n";
$sitemap_index .= "<loc>".$cfg_basehost."/sitemap/sitemap_$i.xml</loc>\n";
$sitemap_index .= "<lastmod>".date("Y-m-d",time())."T".date("H:i:s+08:00",time())."</lastmod>\n";
$sitemap_index .= "</sitemap>\n";
}
$sitemap_index .= "</sitemapindex>";
$indexmap = fopen(dirname(__FILE__)."/../".$filename."/sitemap_index.xml", "w");
fwrite($indexmap, $sitemap_index);
fclose($indexmap);
ShowMsg("成功生成地图索引:<a href='".$cfg_basehost."/".$filename."/sitemap_index.xml' target='_blank'>/".$filename."/sitemap_index.xml</a>","javascript:;");
//首页、栏目列表sitemap_0.xml
$sitemap_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap_1 .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$sitemap_1 .= "<url>\n";
$sitemap_1 .= "<loc>".$cfg_basehost."/</loc>\n";
$sitemap_1 .= "<lastmod>".date("Y-m-d",time())."T".date("H:i:s+08:00",time())."</lastmod>\n";
$sitemap_1 .= "<changefreq>always</changefreq>\n";
$sitemap_1 .= "<priority>1.0</priority>\n";
$sitemap_1 .= "</url>\n";
$dsql->SetQuery("Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath from `#@__arctype` where ishidden<>1 order by id,sortrank");
$dsql->execute();
while($row_type = $dsql->getarray()){
$sitemap_1 .= "<url>\n";
$iTypeUrl = $tl->GetOneTypeUrl($row_type);
$iTypeUrl = count(explode("http://",$iTypeUrl))>1 ? $iTypeUrl : $cfg_basehost.$iTypeUrl;
$sitemap_1 .= "<loc>".$iTypeUrl."</loc>\n";
$sitemap_1 .= "<lastmod>".date("Y-m-d",time())."T".date("H:i:s+08:00",time())."</lastmod>\n";
$sitemap_1 .= "<changefreq>daily</changefreq>\n";
$sitemap_1 .= "<priority>0.9</priority>\n";
$sitemap_1 .= "</url>\n";
//$sitemap_1 .= getSonClass($row_type["id"]);
}
$sitemap_1 .= "</urlset>";
$classmap = fopen(dirname(__FILE__)."/../".$filename."/sitemap_0.xml", "w");
fwrite($classmap, $sitemap_1);
fclose($classmap);
ShowMsg("成功生成首页、栏目列表地图:<a href='".$cfg_basehost."/".$filename."/sitemap_0.xml' target='_blank'>/".$filename."/sitemap_0.xml</a>","javascript:;");
//所有文章sitemap_(1-*).xml
$limit_st = 0;
for($page_num=1; $page_num<=$pagenumber; $page_num++){
$sitemap = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$query = "Select arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
from `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
where arc.ismake=1 order by pubdate limit $limit_st,$perpageurl";
$dsql->SetQuery($query);
$dsql->execute();
while($row_url = $dsql->getarray()){
//自动识别动态页和静态页
$row_url["arcurl"] = GetFileUrl($row_url["id"],$row_url["typeid"],$row_url["senddate"],$row_url["title"],$row_url["ismake"],$row_url["arcrank"],$row_url["namerule"],$row_url["typedir"],$row_url["money"],$row_url['filename'],$row_url["moresite"],$row_url["siteurl"],$row_url["sitepath"]);
$row_url["fullurl"] = $cfg_basehost.$row_url["arcurl"];
if($GLOBALS['cfg_multi_site'] == 'Y') $row_url["fullurl"] = $row_url["arcurl"];
$link = $row_url["fullurl"];
$times = $row_url['senddate'] ;
$lastmodified=date("Y-m-d",$times)."T".date("H:i:s+08:00",$times);
//生成更新频率和更新指数
$priority="0.8";
//生成sitemap
$sitemap .= "<url>\n";
$sitemap .= "<loc>$link</loc>\n";
$sitemap .= "<lastmod>$lastmodified</lastmod>\n";
$sitemap .= "<changefreq>$changefreq</changefreq>\n";
$sitemap .= "<priority>$priority</priority>\n";
$sitemap .= "</url>\n";
}
$sitemap .= "</urlset>";
$urlmap = fopen(dirname(__FILE__)."/../".$filename."/sitemap_".$page_num.".xml","w");
fwrite($urlmap,$sitemap);
fclose($urlmap);
ShowMsg("成功生成文章列表地图:<a href='".$cfg_basehost."/".$filename."/sitemap_".$page_num.".xml' target='_blank'>/".$filename."/sitemap_".$page_num.".xml</a><br>共".$row_sum['mycount']."条记录,每页".$perpageurl."条,当前".$page_num."/".$pagenumber."页","javascript:;");
$limit_st = $limit_st + $perpageurl;
}
ShowMsg("全部生成成功!","javascript:;");
exit();
}
?>
生成老是会卡住。。大概一百多万条数据。。
/**
* 生成Sitemap操作
*
* @version $Id: google_sitemap.php 1 10:00 2011年9月19日Z SSKCN $
* @package SSKCN.Administrator
* @copyright Copyright (c) 2011 - 2013, SSKCN, Inc.
* @license http://www.sskcn.com/license.html
* @link http://www.sskcn.com/
*/
require_once(dirname(__FILE__)."/config.php");
CheckPurview('plus_Sitemap');
require_once(DEDEINC."/typelink.class.php");
$tl = new TypeLink(0);
function DateDiff($interval, $date1, $date2) {
$time_difference = $date2 - $date1;
switch ($interval) {
case "y": $retval = bcdiv($time_difference, 31536000); break;
case "m": $retval = bcdiv($time_difference, 2592000); break;
case "w": $retval = bcdiv($time_difference, 604800); break;
case "d": $retval = bcdiv($time_difference, 86400); break;
case "h": $retval = bcdiv($time_difference, 3600); break;
case "n": $retval = bcdiv($time_difference, 60); break;
case "s": $retval = $time_difference; break;
}
return $retval;
}
function getSonClass($ID) {
$dsql = new DedeSql(false);
$dsql->SetQuery("Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath from `#@__arctype` where reid='".$ID."' and ishidden<>1 order by id,sortrank");
$dsql->execute($ID);
while($row_class = $dsql->getarray($ID)){
ShowMsg($ID);
$SonClass .= "<url>\n";
$iClassUrl = $tl->GetOneTypeUrl($row_class);
$iClassUrl = count(explode("http://",$iClassUrl))>1 ? $iClassUrl: $cfg_basehost.$iClassUrl;
$SonClass .= "<loc>".$iClassUrl."</loc>\n";
$SonClass .= "<lastmod>".date("Y-m-d",time())."T".date("H:i:s+08:00",time())."</lastmod>\n";
$SonClass .= "<changefreq>daily</changefreq>\n";
$SonClass .= "<priority>0.9</priority>\n";
$SonClass .= "</url>\n";
getSonClass($row_class["id"]);
}
return $SonClass;
}
function MK_Dir($path,$pathname){
if(!file_exists($path)){
createDir(dirname($path));
mkdir($path, 0775);
ShowMsg("成功创建目录".$pathname,"javascript:;");
}
}
if(empty($dopost)){
include DEDEADMIN.'/templets/google_sitemap.htm';
}else if($dopost=="make"){
//取得数目
$dsql->SetQuery("Select count(*) as mycount from `#@__archives` where ismake=1");
$dsql->execute();
$row_sum = $dsql->getarray();
if(($sumurl > $row_sum['mycount']) || empty($sumurl)){
$sumurl = $row_sum['mycount'];
}
$pagenum = intval($sumurl/$perpageurl);
$pagenumber = $pagenum;
if($pagenum < ($sumurl/$perpageurl)){
$pagenumber = $pagenum + 1;
}
//创建目录
MK_Dir(dirname(__FILE__)."/../".$filename,$filename);
//索引页sitemap_index.xml
$sitemap_index = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap_index .= "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
for($i=0; $i <= $pagenumber; $i++){
$sitemap_index .= "<sitemap>\n";
$sitemap_index .= "<loc>".$cfg_basehost."/sitemap/sitemap_$i.xml</loc>\n";
$sitemap_index .= "<lastmod>".date("Y-m-d",time())."T".date("H:i:s+08:00",time())."</lastmod>\n";
$sitemap_index .= "</sitemap>\n";
}
$sitemap_index .= "</sitemapindex>";
$indexmap = fopen(dirname(__FILE__)."/../".$filename."/sitemap_index.xml", "w");
fwrite($indexmap, $sitemap_index);
fclose($indexmap);
ShowMsg("成功生成地图索引:<a href='".$cfg_basehost."/".$filename."/sitemap_index.xml' target='_blank'>/".$filename."/sitemap_index.xml</a>","javascript:;");
//首页、栏目列表sitemap_0.xml
$sitemap_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap_1 .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$sitemap_1 .= "<url>\n";
$sitemap_1 .= "<loc>".$cfg_basehost."/</loc>\n";
$sitemap_1 .= "<lastmod>".date("Y-m-d",time())."T".date("H:i:s+08:00",time())."</lastmod>\n";
$sitemap_1 .= "<changefreq>always</changefreq>\n";
$sitemap_1 .= "<priority>1.0</priority>\n";
$sitemap_1 .= "</url>\n";
$dsql->SetQuery("Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath from `#@__arctype` where ishidden<>1 order by id,sortrank");
$dsql->execute();
while($row_type = $dsql->getarray()){
$sitemap_1 .= "<url>\n";
$iTypeUrl = $tl->GetOneTypeUrl($row_type);
$iTypeUrl = count(explode("http://",$iTypeUrl))>1 ? $iTypeUrl : $cfg_basehost.$iTypeUrl;
$sitemap_1 .= "<loc>".$iTypeUrl."</loc>\n";
$sitemap_1 .= "<lastmod>".date("Y-m-d",time())."T".date("H:i:s+08:00",time())."</lastmod>\n";
$sitemap_1 .= "<changefreq>daily</changefreq>\n";
$sitemap_1 .= "<priority>0.9</priority>\n";
$sitemap_1 .= "</url>\n";
//$sitemap_1 .= getSonClass($row_type["id"]);
}
$sitemap_1 .= "</urlset>";
$classmap = fopen(dirname(__FILE__)."/../".$filename."/sitemap_0.xml", "w");
fwrite($classmap, $sitemap_1);
fclose($classmap);
ShowMsg("成功生成首页、栏目列表地图:<a href='".$cfg_basehost."/".$filename."/sitemap_0.xml' target='_blank'>/".$filename."/sitemap_0.xml</a>","javascript:;");
//所有文章sitemap_(1-*).xml
$limit_st = 0;
for($page_num=1; $page_num<=$pagenumber; $page_num++){
$sitemap = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$query = "Select arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
from `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
where arc.ismake=1 order by pubdate limit $limit_st,$perpageurl";
$dsql->SetQuery($query);
$dsql->execute();
while($row_url = $dsql->getarray()){
//自动识别动态页和静态页
$row_url["arcurl"] = GetFileUrl($row_url["id"],$row_url["typeid"],$row_url["senddate"],$row_url["title"],$row_url["ismake"],$row_url["arcrank"],$row_url["namerule"],$row_url["typedir"],$row_url["money"],$row_url['filename'],$row_url["moresite"],$row_url["siteurl"],$row_url["sitepath"]);
$row_url["fullurl"] = $cfg_basehost.$row_url["arcurl"];
if($GLOBALS['cfg_multi_site'] == 'Y') $row_url["fullurl"] = $row_url["arcurl"];
$link = $row_url["fullurl"];
$times = $row_url['senddate'] ;
$lastmodified=date("Y-m-d",$times)."T".date("H:i:s+08:00",$times);
//生成更新频率和更新指数
$priority="0.8";
//生成sitemap
$sitemap .= "<url>\n";
$sitemap .= "<loc>$link</loc>\n";
$sitemap .= "<lastmod>$lastmodified</lastmod>\n";
$sitemap .= "<changefreq>$changefreq</changefreq>\n";
$sitemap .= "<priority>$priority</priority>\n";
$sitemap .= "</url>\n";
}
$sitemap .= "</urlset>";
$urlmap = fopen(dirname(__FILE__)."/../".$filename."/sitemap_".$page_num.".xml","w");
fwrite($urlmap,$sitemap);
fclose($urlmap);
ShowMsg("成功生成文章列表地图:<a href='".$cfg_basehost."/".$filename."/sitemap_".$page_num.".xml' target='_blank'>/".$filename."/sitemap_".$page_num.".xml</a><br>共".$row_sum['mycount']."条记录,每页".$perpageurl."条,当前".$page_num."/".$pagenumber."页","javascript:;");
$limit_st = $limit_st + $perpageurl;
}
ShowMsg("全部生成成功!","javascript:;");
exit();
}
?>
生成老是会卡住。。大概一百多万条数据。。