protected function readFile($filename, $locking = true)
    {
        if (!($fileHandle = @fopen($filename, 'rb'))) {
            throw new Doozr_Cache_Service_Exception(
                sprintf('Can\'t access cache file "%s". Check access rights and path.', $filename)
            );
        }

        // File locking (shared lock)
        ($locking === true) ?: flock($fileHandle, LOCK_SH);

        // File format: 1st line: expiration date - 2nd line: user data - 3rd+ lines: cache data
        $expire = trim(fgets($fileHandle, 12));

        if ($this->maxUserdataLineLength == 0) {
            $userdata = trim(fgets($fileHandle));
        } else {
            $userdata = trim(fgets($fileHandle, $this->maxUserdataLineLength));
        }

        $buffer = '';
        while (!feof($fileHandle)) {
            $buffer .= fread($fileHandle, 8192);
        }

        $value = $this->decode($buffer);

        // Unlocking
        ($locking === true) ?: flock($fileHandle, LOCK_UN);

        fclose($fileHandle);

        // last usage date used by the gc - maxlifetime touch without second param produced stupid entries...
        touch($filename, time());

        $this->clear();

        // Return the result
        return [
            $expire,
            $userdata,
            $value,
        ];
    }
protected function readFile($filename, $locking = true)
    {
        if (!($fileHandle = @fopen($filename, 'rb'))) {
            throw new Doozr_Cache_Service_Exception(
                sprintf('Can\'t access cache file "%s". Check access rights and path.', $filename)
            );
        }

        // File locking (shared lock)
        ($locking === true) ?: flock($fileHandle, LOCK_SH);

        // File format: 1st line: expiration date - 2nd line: user data - 3rd+ lines: cache data
        $expire = trim(fgets($fileHandle, 12));

        if ($this->maxUserdataLineLength == 0) {
            $userdata = trim(fgets($fileHandle));
        } else {
            $userdata = trim(fgets($fileHandle, $this->maxUserdataLineLength));
        }

        $buffer = '';
        while (!feof($fileHandle)) {
            $buffer .= fread($fileHandle, 8192);
        }

        $value = $this->decode($buffer);

        // Unlocking
        ($locking === true) ?: flock($fileHandle, LOCK_UN);

        fclose($fileHandle);

        // last usage date used by the gc - maxlifetime touch without second param produced stupid entries...
        touch($filename, time());

        $this->clear();

        // Return the result
        return [
            $expire,
            $userdata,
            $value,
        ];
    }
protected function readFile ( $ filename , $ locking = true ) { if ( ! ( $ fileHandle = @ fopen ( $ filename , 'rb' ) ) ) { throw new Doozr_Cache_Service_Exception ( sprintf ( 'Can\'t access cache file "%s". Check access rights and path.' , $ filename ) ) ; } // File locking (shared lock) ( $ locking === true ) ? : flock ( $ fileHandle , LOCK_SH ) ; // File format: 1st line: expiration date - 2nd line: user data - 3rd+ lines: cache data $ expire = trim ( fgets ( $ fileHandle , 12 ) ) ; if ( $ this -> maxUserdataLineLength == 0 ) { $ userdata = trim ( fgets ( $ fileHandle ) ) ; } else { $ userdata = trim ( fgets ( $ fileHandle , $ this -> maxUserdataLineLength ) ) ; } $ buffer = '' ; while ( ! feof ( $ fileHandle ) ) { $ buffer .= fread ( $ fileHandle , 8192 ) ; } $ value = $ this -> decode ( $ buffer ) ; // Unlocking ( $ locking === true ) ? : flock ( $ fileHandle , LOCK_UN ) ; fclose ( $ fileHandle ) ; // last usage date used by the gc - maxlifetime touch without second param produced stupid entries... touch ( $ filename , time ( ) ) ; $ this -> clear ( ) ; // Return the result return [ $ expire , $ userdata , $ value , ] ; }
Reads a file from filesystem, modifies its "last access time" and returns values structured.

@param string $filename The filename to read
@param bool   $locking  TRUE to lock file exclusive, FALSE to do not

@author Benjamin Carl <opensource@clickalicious.de>

@return array The data of the data-set prepared in a clean array structure

@throws Doozr_Cache_Service_Exception
Reads a file from filesystem modifies its last access time and returns values structured .