當前位置: 首頁>>代碼示例>>PHP>>正文


PHP cron::_nextLowerVal方法代碼示例

本文整理匯總了PHP中cron::_nextLowerVal方法的典型用法代碼示例。如果您正苦於以下問題:PHP cron::_nextLowerVal方法的具體用法?PHP cron::_nextLowerVal怎麽用?PHP cron::_nextLowerVal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cron的用法示例。


在下文中一共展示了cron::_nextLowerVal方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: due

    /**
     * This is the heart of the class
     * @param time $tLast last time at which the command was completed
     * @param time $tNow  the reference time, usually the current time stamp
     * @param string $sSpec the specifier in the usual crontab format
     * @return boolean
     * TRUE if a timestamp exists between $tLast and $tNow fulfilling the $sSpec criteria.
     * returns FALSE otherwise
     */
    function due($tLast, $tNow, $sSpec)
    {

        // this array describes the classic crontab format
        // for internal use the elements are listed in reverse order
        $arSeg = array("wday", "mon",
                       "mday", "hours",
                       "minutes");
        // alternate crontab format includes year
        // this format is internally not (yet) supported!!!
        /* $arSeg = array("year", "wday",
                          "mon",  "mday",
                          "hours", "minutes");
        */

        // this array contains the offset in case for the carry over status
        // see below for the determination of the carry over status
        $arPeriod = array("wday"    => 7,
                          "mon"     => 12,
                          "mday"    =>
                              array(31, 28, 31, 30, 31, 30,
                                    31, 31, 30, 31, 30, 31),
                          "hours"   => 24,
                          "minutes" => 60);

        $arTime = array("wday"    =>    604800,  //   7 * 24 * 60 * 60
                        "mon"     =>  31536000,  // 365 * 24 * 60 * 60
                        "mday"    =>
                              array(31 * 86400,  //  31 * 24 * 60 * 60
                                    28 * 86400,
                                    31 * 86400,
                                    30 * 86400,
                                    31 * 86400,
                                    30 * 86400,
                                    31 * 86400,
                                    31 * 86400,
                                    30 * 86400,
                                    31 * 86400,
                                    30 * 86400,
                                    31 * 86400),
                        "hours"   =>     86400,  //       24 * 60 * 60
                        "minutes" =>      3600); //            60 * 60


        $iSeg = 0;        // segment index
        $iCmpVal = 0;     // compare value

        // these lines added in 0.2.5
        $bStatus = FALSE; // procedure status
        $iPFaktor = 0;    // period factor
        $iTFaktor = 0;    // time factor

        if ($tNow == NULL)  $tNow = time();
        // this line added in version 0.2.2
        if ($tLast == NULL) return FALSE;

        // convert strings to time
        if (is_string($tLast)) $tLast = strtotime($tLast);
        if (is_string($tNow))  $tNow = strtotime($tNow);

        if ($tNow < $tLast) return FALSE;

        // convert time variables to arrays
        $arLast = getdate($tLast);
        $arNow  = getdate($tNow);
        $arSpec = array_reverse(explode(" ", $sSpec));

        // walk through segments of crontab specifier
        for ($iSeg = 0; $iSeg < count($arSeg); $iSeg ++) {
            // obtain segment key
            $sSeg = $arSeg[$iSeg];
            // does specifier segment contain '*'?
            if (strstr($arSpec[$iSeg], "*") != FALSE) {
                // week days need special treatment
                if ($sSeg == "wday") $iCmpVal = $arLast[$sSeg];
                // use same segment of time reference
                else $iCmpVal = $arNow[$sSeg];
            // specifier segment contains specific criteria
            } else {
                // get reference value
                $iCmpVal = cron::_nextLowerVal($arSpec[$iSeg], $arNow[$sSeg]);
            } /* endif */

            // this section completely changed in 0.2.5
            // obtain period factor
            $iPFactor = $arPeriod[$sSeg];
            // numbers of days per month are always different ...
            if ($sSeg == "mday")
                $iPFactor = $iPFactor[$arLast["mon"]];

            // obtain period time factor
//.........這裏部分代碼省略.........
開發者ID:nistormihai,項目名稱:Newscoop,代碼行數:101,代碼來源:Cron.php


注:本文中的cron::_nextLowerVal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。