記録

昨日の続き、cronPHP(´Д`)、一つのジョブから複数のPHPファイルを実行させる方法。

<?php
//5分刻みに対して有効な無限クローン 処理が負荷の場合どうなるかは知りません。
date_default_timezone_set('Asia/Tokyo');
class cron{

    public function d_m($obj)
    {
            if($obj->m==="*")return true;
            if(preg_match("/,/",$obj->m))return $this->comma($obj->m,date("m"));
            if((int)$obj->m === (int)date("m"))return true;

            return false;
    }

    public function d_d($obj)
    {
            if($obj->d==="*")return true;
            if(preg_match("/,/",$obj->d))return $this->comma($obj->d,date("d"));
            if((int)$obj->d === (int)date("d"))return true;

            return false;
    }

    public function d_H($obj)
    {
            if(preg_match("/\*\/[0-9]{1,2}/",$obj->H)){
                $H = explode("/",$obj->H);
                if((int)$H[1]>0 && ((int)date("H") % (int)$H[1])===0)return true;
            }else{
                if($obj->H==="*")return true;
                if(preg_match("/,/",$obj->H))return $this->comma($obj->H,date("H"));
                if((int)$obj->H === (int)date("H"))return true;

            }
            return false;
    }

    public function d_i($obj)
    {
            if(preg_match("/\*\/[0-9]{1,2}/",$obj->i)){
                $i = explode("/",$obj->i);
                if((int)$i[1]>0 && ((int)date("i") % (int)$i[1])===0)return true;
            }else{
                if($obj->i==="*")return true;
                if(preg_match("/,/",$obj->i))return $this->comma($obj->i,date("i"));
                if((int)$obj->i === (int)date("i"))return true;

            }
            return false;
    }

    //曜日 0=日曜日 6=土曜日
    public function d_w($obj)
    {
            if((int)$obj->w[date("w")]===1)return true;
            return false;
    }

    public  function comma($c="",$t=""){
        if($c==="")return false;
        if($t==="")return false;
        $flg = false;
        foreach(explode(",",$c) as $cc){
            if((int)$cc===(int)$t)$flg = true;
        }
        return $flg;
    }


    public function d_command($obj){
        if($obj->command){
            exec($obj->command . " > /dev/null &");
        }
        return true;
    }

}
if ($argv[1]) {
   $filename = $argv[1];
    if(is_file($filename)){
        $jsn = json_decode(file_get_contents($filename));
        $cron = new cron();
        try {
            foreach($jsn as $obj){
                if($cron->d_m($obj)){
                    if($cron->d_d($obj)){
                        if($cron->d_H($obj)){
                            if($cron->d_i($obj)){
                                if($cron->d_w($obj)){
                                    $cron->d_command($obj);//波動拳{{{{
                                }
                            }
                        }
                    }
                }
            }
        } catch (\Throwable $th) {
            print $th->getMessage();
        }
    }
}

 
この頃、ネタがないので手抜き投稿です。気づいた人どのぐらいいるのだろうか?
Qittaに公開しました。https://qiita.com/question909/items/8f1df9b62ab4fba76243







    cronPHPを作ってみた朝の続き。前のページ

    Qiitaでまぁまぁ閲覧されて嬉しかったり(´∀`)次のページ

    関連記事

    1. 記録

      本:ホモ・デウス/テクノロジーとサピエンスの未来

      昨日の帰り書店でこれが陳列されていて・・・。迷いに迷って、結局購入…

    2. 記録

      コーディング:プログラムコードを書くこと。

      コーディング:プログラムコードを書くこと。 誰でもプログラムは書く…

    3. 記録

      これからは独自のサイトはあまり要らないのかも。

      これからは独自のサイトはあまり要らないのかも。サイトの代わりに、こ…

    4. 記録

      今日から。

      今日からコード(プログラマー見習い)書きに戻ります。現役で書いていた…

    5. 記録

      魂の叫びのような歌を歌う人。

      魂の叫びのような歌を歌う人はあまりいない中のひとりにamazaras…

    6. 記録

      何者:人の子。この人にも親がいるだと思ったら。

      暑い日が続いています(今日は雨)。この頃、冷たいものと扇風機が欠か…

    2015年6月
    1234567
    891011121314
    15161718192021
    22232425262728
    2930  

    カテゴリー

    アーカイブ

    PAGE TOP