PHP修改crontab

PHP修改crontab

作者:admin |  时间:2014-07-02 |  浏览:663 |  0 条评论
<?php
 
function timingPublish($oldPt,$id) {
    $command = '';
    $query = mysql_query("select defaultTiming from src_sources where id='$id'");
    $row = mysql_fetch_array($query, MYSQL_ASSOC);
    $defaultTiming = $row['defaultTiming'];
    $timeArray = explode(':',$defaultTiming);
    $minite = $timeArray[1];
    $hour = $timeArray[0];
    $command = $minite." ".$hour." * * * wget -O /dev/null ".CODE_URI."cms_column.shtml?tab=list";
    if ($defaultTiming != '00:00:00') {
        if ($oldPt == '00:00:00') {
            //如果原来的发布时间为空,只需要添加新命令
            $f=popen("crontab -e","w");
            fputs($f,"i");
            fputs($f,$command);
            fputs($f,"\n");
            fputs($f,chr(27));
            fputs($f,":wq\r");
            pclose($f);
        } else {
            //搜索到旧命令,并修改
            $f=popen("crontab -e","w");
            fputs($f,"/");
            fputs($f,"sourceId=".$id);
            fputs($f,"\n");
            fputs($f,"dd");
            fputs($f,"i");
            fputs($f,$command."");
            fputs($f,"\n");
            fputs($f,chr(27));
            fputs($f,":wq\r");
            pclose($f);
        }
    } else {
        if ($oldPt != '00:00:00') {
            $f=popen("crontab -e","w");
            fputs($f,"/");
            fputs($f,"sourceId=".$id);
            fputs($f,"\n");
            fputs($f,"dd");
            fputs($f,":wq\r");
            pclose($f);
        }
    }
}

发表评论

电子邮件地址不会被公开。

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>