src/xPDO/Cache/xPDOCacheManager.php
public function writeFile($filename, $content, $mode= 'wb', $options= array()) {
        $written= false;
        if (!is_array($options)) {
            $options = is_scalar($options) && !is_bool($options) ? array('new_folder_permissions' => $options) : array();
        }
        $dirname= dirname($filename);
        if (!file_exists($dirname)) {
            $this->writeTree($dirname, $options);
        }
        $mode = str_replace('+', '', $mode);
        switch ($mode[0]) {
            case 'a':
                $append = true;
                break;
            default:
                $append = false;
                break;
        }
        $fmode = (strlen($mode) > 1 && in_array($mode[1], array('b', 't'))) ? "a{$mode[1]}" : 'a';
        $file= @fopen($filename, $fmode);
        if ($file) {
            if ($append === true) {
                $written= fwrite($file, $content);
            } else {
                $locked = false;
                $attempt = 1;
                $attempts = (integer) $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 1);
                $attemptDelay = (integer) $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000);
                while (!$locked && ($attempts === 0 || $attempt <= $attempts)) {
                    if ($this->getOption('use_flock', $options, true)) {
                        $locked = flock($file, LOCK_EX | LOCK_NB);
                    } else {
                        $lockFile = $this->lockFile($filename, $options);
                        $locked = $lockFile != false;
                    }
                    if (!$locked && $attemptDelay > 0 && ($attempts === 0 || $attempt < $attempts)) {
                        usleep($attemptDelay);
                    }
                    $attempt++;
                }
                if ($locked) {
                    fseek($file, 0);
                    ftruncate($file, 0);
                    $written= fwrite($file, $content);
                    if ($this->getOption('use_flock', $options, true)) {
                        flock($file, LOCK_UN);
                    } else {
                        $this->unlockFile($filename, $options);
                    }
                }
            }
            @fclose($file);
        }
        return ($written !== false);
    }
public function writeFile($filename, $content, $mode= 'wb', $options= array()) {
        $written= false;
        if (!is_array($options)) {
            $options = is_scalar($options) && !is_bool($options) ? array('new_folder_permissions' => $options) : array();
        }
        $dirname= dirname($filename);
        if (!file_exists($dirname)) {
            $this->writeTree($dirname, $options);
        }
        $mode = str_replace('+', '', $mode);
        switch ($mode[0]) {
            case 'a':
                $append = true;
                break;
            default:
                $append = false;
                break;
        }
        $fmode = (strlen($mode) > 1 && in_array($mode[1], array('b', 't'))) ? "a{$mode[1]}" : 'a';
        $file= @fopen($filename, $fmode);
        if ($file) {
            if ($append === true) {
                $written= fwrite($file, $content);
            } else {
                $locked = false;
                $attempt = 1;
                $attempts = (integer) $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 1);
                $attemptDelay = (integer) $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000);
                while (!$locked && ($attempts === 0 || $attempt <= $attempts)) {
                    if ($this->getOption('use_flock', $options, true)) {
                        $locked = flock($file, LOCK_EX | LOCK_NB);
                    } else {
                        $lockFile = $this->lockFile($filename, $options);
                        $locked = $lockFile != false;
                    }
                    if (!$locked && $attemptDelay > 0 && ($attempts === 0 || $attempt < $attempts)) {
                        usleep($attemptDelay);
                    }
                    $attempt++;
                }
                if ($locked) {
                    fseek($file, 0);
                    ftruncate($file, 0);
                    $written= fwrite($file, $content);
                    if ($this->getOption('use_flock', $options, true)) {
                        flock($file, LOCK_UN);
                    } else {
                        $this->unlockFile($filename, $options);
                    }
                }
            }
            @fclose($file);
        }
        return ($written !== false);
    }
public function writeFile ( $ filename , $ content , $ mode = 'wb' , $ options = array ( ) ) { $ written = false ; if ( ! is_array ( $ options ) ) { $ options = is_scalar ( $ options ) && ! is_bool ( $ options ) ? array ( 'new_folder_permissions' => $ options ) : array ( ) ; } $ dirname = dirname ( $ filename ) ; if ( ! file_exists ( $ dirname ) ) { $ this -> writeTree ( $ dirname , $ options ) ; } $ mode = str_replace ( '+' , '' , $ mode ) ; switch ( $ mode [ 0 ] ) { case 'a' : $ append = true ; break ; default : $ append = false ; break ; } $ fmode = ( strlen ( $ mode ) > 1 && in_array ( $ mode [ 1 ] , array ( 'b' , 't' ) ) ) ? "a{$mode[1]}" : 'a' ; $ file = @ fopen ( $ filename , $ fmode ) ; if ( $ file ) { if ( $ append === true ) { $ written = fwrite ( $ file , $ content ) ; } else { $ locked = false ; $ attempt = 1 ; $ attempts = ( integer ) $ this -> getOption ( xPDO :: OPT_CACHE_ATTEMPTS , $ options , 1 ) ; $ attemptDelay = ( integer ) $ this -> getOption ( xPDO :: OPT_CACHE_ATTEMPT_DELAY , $ options , 1000 ) ; while ( ! $ locked && ( $ attempts === 0 || $ attempt <= $ attempts ) ) { if ( $ this -> getOption ( 'use_flock' , $ options , true ) ) { $ locked = flock ( $ file , LOCK_EX | LOCK_NB ) ; } else { $ lockFile = $ this -> lockFile ( $ filename , $ options ) ; $ locked = $ lockFile != false ; } if ( ! $ locked && $ attemptDelay > 0 && ( $ attempts === 0 || $ attempt < $ attempts ) ) { usleep ( $ attemptDelay ) ; } $ attempt ++ ; } if ( $ locked ) { fseek ( $ file , 0 ) ; ftruncate ( $ file , 0 ) ; $ written = fwrite ( $ file , $ content ) ; if ( $ this -> getOption ( 'use_flock' , $ options , true ) ) { flock ( $ file , LOCK_UN ) ; } else { $ this -> unlockFile ( $ filename , $ options ) ; } } } @ fclose ( $ file ) ; } return ( $ written !== false ) ; }
Writes a file to the filesystem.

@access public
@param string $filename The absolute path to the location the file will
be written in.
@param string $content The content of the newly written file.
@param string $mode The php file mode to write in. Defaults to 'wb'. Note that this method always
uses a (with b or t if specified) to open the file and that any mode except a means existing file
contents will be overwritten.
@param array $options An array of options for the function.
@return int|bool Returns the number of bytes written to the file or false on failure.
Writes a file to the filesystem .