欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

crontab dedecms 织梦 定时更新主页

shiping1 的头像

dedecms 定时更新主页

  这两天公司要写个定时采集的程序,我顺便研究了下定时更新网站首页,这里先记录下

  我用的是centos5.3 dedecms5.5 步骤如下:

  第一:分离dedecms的生成主页的文件,重命名文件(我用的是mh.php),上传到管理目录下(dede)

  这个文件主要是写入session,自定义参数,以便进行管理员操作。要保证cron能执行此文件,首先自己要在浏览器上打开这个文件看看能不能正常运行,如果可以再继续下一步。

 #!/usr/local/webserver/php/bin/php -q
<?php
session_start();
$_SESSION['dede_admin_id'] = 'admin';
$_SESSION['dede_admin_type'] = 10;
$_SESSION['dede_admin_channel'] = '0';
$_SESSION['dede_admin_name'] = 'admin';
$_SESSION['dede_admin_purview'] = 'admin_AllowAll';
require_once(dirname(__FILE__)."/config.php");
CheckPurview('sys_MakeHtml');
require_once(DEDEINC."/arc.partview.class.php");

 $position = "../index.html";
 $templet = "default/index.htm";
 $homeFile = DEDEADMIN."/".$position;
 $homeFile = str_replace("\\","/",$homeFile);
 $homeFile = str_replace("//","/",$homeFile);
 $fp = fopen($homeFile,"w") or die("你指定的文件名有问题,无法创建文件");
 fclose($fp);
 if($saveset==1)   $iquery = "update `#@__homepageset` set templet='$templet',position='$position' ";
  $dsql->ExecuteNoneQuery($iquery);  $templet = str_replace("{style}",$cfg_df_style,$templet);
 $pv = new PartView();
 $GLOBALS['_arclistEnv'] = 'index';
 $pv->SetTemplet($cfg_basedir.$cfg_templets_dir."/".$templet);
 $pv->SaveToHtml($homeFile);
 echo "成功更新主页HTML:".date('Y-m-d h:i:s')."\n";
 exit()
?>

第二:linux系统下创建cron(详细介绍请参考我另一篇文章http://blog.sina.com.cn/s/blog_601d49a30100fmpj.html)

命令:

00 */2 * * * path of php(你的php的路径) path of file(你要执行的文件的路径)>>path of log(日志存放的路径)

这里设定的是 每天间隔两个小时更新一次主页

以后就系统就会定时更新主页了,如果你是一个采集站,首页内容是随机调出来的,这种方法应该能增加收录

来自 http://it.chinawin.net/os/article-2a70.html

普通分类: