Show
Ignore:
Timestamp:
10/01/08 04:26:27 (3 months ago)
Author:
sabel
Message:

clean-up

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/sabel/trunk/lib/UserCache.php

    r20329 r20334  
    2929  { 
    3030    $path = $this->getPath($userId); 
    31     if (is_file($path)) { 
    32       include ($path); 
    33       if ($this->check($data)) { 
    34         return $data; 
    35       } else { 
    36         unlink($path); 
    37         return false; 
    38       } 
    39     } else { 
    40       return false; 
    41     } 
     31    return (is_file($path)) ? $this->_read($path) : false; 
    4232  } 
    4333   
    4434  public function lock($userId, $mode = "ab+") 
    4535  { 
    46     $i = 0; 
    4736    $path = $this->getPath($userId); 
     37    $fp   = fopen($path, $mode); 
     38    $data = $this->_read($path); 
    4839     
    49     while (++$i < 5) { 
    50       $fp = fopen($path, $mode); 
    51       if (flock($fp, LOCK_EX)) { 
    52         ftruncate($fp, 0); 
    53         return $fp; 
    54       } else { 
    55         usleep(mt_rand(50000, 500000)); 
    56       } 
     40    flock($fp, LOCK_EX); 
     41    ftruncate($fp, 0); 
     42     
     43    return array($fp, $data); 
     44  } 
     45   
     46  protected function _read($path) 
     47  { 
     48    include ($path); 
     49    if (isset($data) && $this->check($data)) { 
     50      return $data; 
     51    } else { 
     52      return false; 
    5753    } 
    58      
    59     return false; 
    6054  } 
    6155