Ignore:
Timestamp:
Nov 25, 2014 10:33:58 AM (10 years ago)
Author:
dungnv
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/helpers/lockfile_helper.php

    r620 r621  
    33if ( ! function_exists('createLockFile'))
    44{
    5         function createLockFile ($lockFilePrefix, $maxReach, $timeToUnlock, $lockFilePath = '', $checkLockOnly = 0, $colSep = '|')
     5        function createLockFile ($lockFilePrefix, $maxReach, $timeToUnlock, $lockFilePath = '', $checkLockOnly = FALSE, $colSep = '|')
    66        {
    77                $currentTimeStamp = time();
     
    2323       
    2424                $timeDiffMin = $lastTimeLock != '' ? dateDifference(date('Y-m-d H:i:s',$currentTimeStamp), date('Y-m-d H:i:s',$lastTimeLock), '%i') : 0;
    25        
    26                 if ($lockCount < $maxReach && $timeDiffMin < $timeToUnlock && $checkLockOnly == 0) {
     25
     26                if ($lockCount < $maxReach && $timeDiffMin < $timeToUnlock && !$checkLockOnly) {
    2727                        $lockCount ++;
    2828                        $isLocked = $lockCount < $maxReach ? 0:1;
     
    3030                }
    3131                else if ($timeDiffMin > $timeToUnlock) {
    32                         $lockCount = 0;
     32                        $lockCount = 1;
    3333                        $isLocked = 0;
    3434                        $ready = 1;
     
    4444                }
    4545       
    46                 return $isLocked;
     46                return (int)$isLocked;
    4747        }
    4848}
     
    5252        function releaseLockFile ($lockFilePrefix, $lockFilePath = '')
    5353        {
    54                 $filePath = $lockFilePrefix.'_lock';
     54                $filePath = $lockFilePath.$lockFilePrefix.'_lock';
    5555                $fileExisted = file_exists($filePath);
    5656                if ($fileExisted) {
     
    8181                $datetime2 = date_create($date_2);
    8282
    83                 $interval = date_diff($datetime1, $datetime2);
    84 
    85                 return $interval->format($differenceFormat);
    86 
     83                $diff = date_diff($datetime1, $datetime2);
     84                $total = 0;
     85                switch( $differenceFormat){
     86                        case "%y":
     87                                $total = $diff->y + $diff->m / 12 + $diff->d / 365.25; break;
     88                        case "%m":
     89                                $total= $diff->y * 12 + $diff->m + $diff->d/30 + $diff->h / 24;
     90                                break;
     91                        case "%a":
     92                                $total = $diff->y * 365.25 + $diff->m * 30 + $diff->d + $diff->h/24 + $diff->i / 60;
     93                                break;
     94                        case "%h":
     95                                $total = ($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h + $diff->i/60;
     96                                break;
     97                        case "%i":
     98                                $total = (($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i + $diff->s/60;
     99                                break;
     100                        case "%s":
     101                                $total = ((($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i)*60 + $diff->s;
     102                                break;
     103                }
     104               
     105                return (int)$total;
     106                /* if( $diff->invert)
     107                        return -1 * $total;
     108                else    return $total; */
    87109        }
    88110}
Note: See TracChangeset for help on using the changeset viewer.