???????????Linux??????????????????????????????????????С??????3??????н??????????????linux?????php???????????????????????????????????μ???????????????????????????????賿?????????????????????

????1??Linux?????php??????

????linux?????php????????????php filename arguments??

????????php ????? ????

????Eg??/usr/local/php/bin/php /home/zhaolincheung/insert_talkcountdata.php

????2????????????????????μ?????????

???????磬????60???????????????

?????????д???shell???talkcount_insert_db.sh???????????????????????????php????????????????shell???£?

#!/bin/sh
for((i=1;i<=60;i++));
do
    echo -e $i":";
    day=`date -d "-"$i" day" "+%Y-%m-%d"`;
    /usr/local/php/bin/php /home/zhaolincheung/insert_talkcountdata.php $day;
    echo "";
done

??????insert_talkcountdata.php????????????????????£?

<?php
????include_once('/data/analys/DB/MyDB.class.php');
????
    //??????????
    $cidArr = array(0??2??1??11??15??14??7??6??4??12??5??13??16??3??9??1001??1002);

    $yesterday = $_SERVER["argv"][1]; //???php???????????
    echo $yesterday . " ";

    //???????????
    foreach($cidArr as $cid){
        //??????
        insert_db($cid??$yesterday);
    }
  
    //????????????????????????????????????
    function insert_db($category?? $date){
        $dateArr = explode("-"?? $date);
        if(checkdate($dateArr[1]?? $dateArr[2]?? $dateArr[0]) == false){
            return false;
        }
        //????????????
        $thisdate = mktime(0?? 0?? 0?? $dateArr[1]?? $dateArr[2]?? $dateArr[0]);
        $nextdate = $thisdate + 3600 * 24;

        $sql = "select talkid??count(*) as msgcount from table1 where postcategoryid=$category ";
        $sql .= " and updatetime >= $thisdate and updatetime < $nextdate group by talkid order by msgcount desc";

        $db = new MyDB();
        $res = $db->query($sql);
      
     //?????????????
        $mc["c20"]=$mc["c10"]=$mc["c6"]=$mc["c5"]=$mc["c4"]=$mc["c3"]=$mc["c2"]=$mc["c1"]=0;
        //???????????????????
        while(($result = $db->fetch_assoc($res)))
        {
          $msgcount = $result["msgcount"];
          if($msgcount > 20)
            $mc["c20"]++;
          else if($msgcount > 10 && $msgcount <= 20)
            $mc["c10"]++;
          else if($msgcount >= 6 && $msgcount <= 10)
            $mc["c6"]++;
          else if($msgcount == 5)
            $mc["c5"]++;
          else if($msgcount == 4)
            $mc["c4"]++;
          else if($msgcount == 3)
            $mc["c3"]++;
          else if($msgcount == 2)
            $mc["c2"]++;
          else if($msgcount == 1)
            $mc["c1"]++;
        }
      
        //insert table 'talkcount'
        $sql_insert = "insert into talkcount(analysisdate??postcategoryid??c20??c10??c6??c5??c4??c3??c2??c1) values('";
        $sql_insert .= $date . "'??";
        $sql_insert .= $category . "??";
        $sql_insert .= $mc["c20"] . "??";
        $sql_insert .= $mc["c10"] . "??";
        $sql_insert .= $mc["c6"] . "??";
        $sql_insert .= $mc["c5"] . "??";
        $sql_insert .= $mc["c4"] . "??";
        $sql_insert .= $mc["c3"] . "??";
        $sql_insert .= $mc["c2"] . "??";
        $sql_insert .= $mc["c1"] . ")";
      
     echo $sql_insert . " ";
      
        $db->query($sql_insert);
      
     $db->close();
    }
?>