open() 개인적인 메소드

See fopen() php function for more info. For now used only internally.
private open ( string $mode ) : boolean | CFile
$mode string Type of access required to the stream
리턴 boolean | CFile Current CFile object on success, 'False' on fail.
 /**
  *                                  
  */
 function rotate()
 {
     if (file_exists($this->_file) && filesize($this->_file) >= $this->_size * 1024 * 1024) {
         //                                                              ,
         //                       ,
         //
         $LockFileHandler = new CFile($this->_file . '.lock');
         $LockFileHandler->open('w');
         if (!$LockFileHandler->isError()) {
             $LockFileHandler->lock(LOCK_EX);
         }
         //                         ,                                  (               )
         //        $renames                          array(exists_files, new_file)
         //           new_file               ,      $renames
         //                     .
         //         ,        $renames                             :
         // array(
         //         array('/var/log/logfile', '/var/log/logfile.1'),
         //         array('/var/log/logfile.1', '/var/log/logfile.2'),
         //         array('/var/log/logfile.2', '/var/log/logfile.3'),
         // )
         //          :
         //    1.                ,                /var/log/logfile.3 -              ,              rename
         //    2.                                                     !
         $cnt = 1;
         $renames = array();
         $filename = $this->_file . '.' . $cnt;
         $cnt++;
         $renames[] = array($this->_file, $filename);
         while (file_exists($filename)) {
             $new_filename = $this->_file . '.' . $cnt;
             $cnt++;
             $renames[] = array($filename, $new_filename);
             $filename = $new_filename;
         }
         //           ,
         $removes = array();
         if (count($renames) > $this->_rotate) {
             $removes = array_slice($renames, $this->_rotate);
             $renames = array_slice($renames, 0, $this->_rotate);
         }
         //
         foreach ($removes as $f) {
             @unlink($f[0]);
         }
         //
         $renames = array_reverse($renames);
         foreach ($renames as $f) {
             rename($f[0], $f[1]);
         }
         //
         touch($this->_file);
         $LockFileHandler->unlock();
         $LockFileHandler->close();
     }
 }
예제 #2
0
 private static function writeCSVRecords($file, $request_id, $records)
 {
     $f = new CFile($file);
     $f->open('a');
     foreach ($records as $fields) {
         $f->write($request_id . self::csv_fields_delimiter);
         $f->write(implode(self::csv_fields_delimiter, $fields));
         $f->write(self::csv_lines_delimiter);
     }
     $f->close();
 }