kernel/private/classes/clusterfilehandlers/ezfs2filehandler.php

Show: inherited
Table of Contents

File containing the eZFS2FileHandler class.

Copyright
Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.  
License
eZ Business Use License Agreement Version 2.0  
Package
kernel  
Version
4.6.0  

\eZFS2FileHandler

Package: Default

This class implements the new version of the FS file handler.

It provides support for stalecache, but can not be used on every platform: support for unlink(), widely used, is not available on windows platforms before PHP 5.3. If you use windows, you can not use this handler unless you use this PHP version (beta at this time). It is perfectly safe to use it on linux / unix

Parent(s)
\eZFSFileHandler
Copyright
Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.  
Version
4.6.0  

Constants

Constant  EXPIRY_TIMESTAMP = 233366400
inherited

This should be defined in eZFS2FileHandler, but due to static members limitations in PHP < 5.3, it is declared here

Inherited from: \eZFSFileHandler::EXPIRY_TIMESTAMP

Properties

Propertypublicvoid  = ''

cacheType

cacheType
Details
Type
Magic
 
Property-read
cacheType  
Propertyprotectedstring|null  $cacheType= 'null'

Cached value of cache type

Default valuenullDetails
Type
string | null
Propertypublic  $filePath= ''
inheritedInherited from: \eZFSFileHandler::$$filePath
Details
Type
n/a
Inherited_from
\eZFSFileHandler::$$filePath  
Propertyprotectedint  $generationStartTimestamp= 'false'

When the instance generates the cached version for a file, this property holds the timestamp at which generation was started. This is used to control a possible generation timeout

Default valuefalseDetails
Type
int
Propertyprotectedint  $generationTimeout= ''

Generation timeout, in seconds. If a generating file exists for more than $generationTimeout seconds, it is taken over

Details
Type
int
Propertypublic  $metaData= 'null'
inheritedInherited from: \eZFSFileHandler::$$metaData
Default valuenullDetails
Type
n/a
Inherited_from
\eZFSFileHandler::$$metaData  
Propertyprotected  $nonExistantStaleCacheHandling= ''

Holds the preferences used when stale cache is activated and no expired file is available.

This is loaded from file.ini, ClusteringSettings.NonExistantStaleCacheHandling

Details
Type
n/a
Propertypublic  $realFilePath= 'null'

holds the real file path. This is only used when we are generating a cache file, in which case $filePath holds the generating cache file name, and $realFilePath holds the real name

Default valuenullDetails
Type
n/a
Propertyprotectedint  $remainingCacheGenerationTime= 'false'

Holds the number of seconds remaining before the generating cache times out

Default valuefalseDetails
Type
int
Propertyprotectedbool  $useStaleCache= 'false'

Indicates that the current cache item is being generated and an old version should be used

Default valuefalseDetails
Type
bool

Methods

methodpublic__construct(  $filePath = false ) : void

Parameters
Name Type Description
$filePath
methodpublic__get(  $propertyName ) : void

Magic getter

Parameters
Name Type Description
$propertyName
methodprivate_cacheType( ) : string

Determines the cache type based on the path

Returns
Type Description
string viewcache, cacheblock or misc
methodpublic_exclusiveLock(  $fname = false ) : void
inherited

Inherited from: \eZFSFileHandler::_exclusiveLock()
Parameters
Name Type Description
$fname
methodprivate_expire( string $path ) : bool
static

Expire the given file

Parameters
Name Type Description
$path string

Path of the file to expire

Returns
Type Description
bool
methodpublic_freeExclusiveLock(  $fname = false ) : void
inherited

Inherited from: \eZFSFileHandler::_freeExclusiveLock()
Parameters
Name Type Description
$fname
methodpublic_mutex( ) : void
inherited

Inherited from: \eZFSFileHandler::_mutex()
methodprivate_recursiveExpire( string $directory ) : void
static

Expires all files in a directory

Parameters
Name Type Description
$directory string
methodpublicabortCacheGeneration( ) : void

Aborts the current cache generation process.

Does so by rolling back the current transaction, which should be the .generating file lock

methodpubliccheckCacheGenerationTimeout( ) : void

Checks if the .generating file was changed, which would mean that generation timed out. If not timed out, refreshes the timestamp so that storage won't be stolen

methodpublicdelete( ) : void

Deletes specified file/directory.

If a directory specified it is deleted recursively.

\public \static

methodpublicdeleteLocal( ) : void

Deletes a file that has been fetched before.

In case of fetching from filesystem does nothing.

\public

methodpubliceZFSFileHandler(  $filePath = false ) : void
inherited

Constructor.

Inherited from: \eZFSFileHandler::eZFSFileHandler()

$filePath File path. If specified, file metadata is fetched in the constructor.

Parameters
Name Type Description
$filePath
methodpublicendCacheGeneration( bool $rename = true ) : bool

Ends the cache generation started by startCacheGeneration().

If $rename is set to true (default), the .generating file is renamed and overwrites the real file. If set to false, the .generating file is removed, and the real file made available.

True should be used when actual data is stored in the standard file and not the .generating one, for instance when using image alias generation.

Parameters
Name Type Description
$rename bool

Rename (true) or delete (false) the generating file

Returns
Type Description
bool
methodpublicexists( ) : void
inherited

Check if given file/dir exists.

Inherited from: \eZFSFileHandler::exists()

NOTE: this function does not interact with filesystem. Instead, it just returns existance status determined in the constructor.

\public

methodpublicfetch(  $noLocalCache = false ) : void
inherited

Fetches file from db and saves it in FS under the same name.

Inherited from: \eZFSFileHandler::fetch()

In case of fetching from filesystem does nothing.

Parameters
Name Type Description
$noLocalCache
methodpublicfetchContents( ) : void
inherited

Returns file contents.

Inherited from: \eZFSFileHandler::fetchContents()

\public \return contents string, or false in case of an error.

methodpublicfetchUnique( ) : string
inherited

Fetches file from db and saves it in FS under unique name.

Inherited from: \eZFSFileHandler::fetchUnique()

In case of fetching from filesystem, does nothing

Returns
Type Description
string The unique file path. on FS, the file path.
methodpublicfileCopy(  $srcPath,  $dstPath ) : void
inherited

Copy file.

Inherited from: \eZFSFileHandler::fileCopy()

\public \static

Parameters
Name Type Description
$srcPath
$dstPath
methodpublicfileDelete( \$path $path, \$fnamePart $fnamePart = false ) : void

Deletes the file(s) or directory matching $path and $fnamePart if given

Parameters
Name Type Description
$path \$path

path of the file to delete

$fnamePart \$fnamePart

path of the file to delete

methodpublicfileDeleteByDirList(  $dirList,  $commonPath,  $commonSuffix ) : void

Delete files located in a directories from dirList, with common prefix specified by commonPath, and common suffix with added wildcard at the end

\public \static \sa fileDeleteByRegex()

Parameters
Name Type Description
$dirList
$commonPath
$commonSuffix
methodpublicfileDeleteByRegex(  $dir,  $fileRegex ) : void
inherited

Delete files matching regex $fileRegex under directory $dir.

Inherited from: \eZFSFileHandler::fileDeleteByRegex()

\public \static \sa fileDeleteByWildcard()

Parameters
Name Type Description
$dir
$fileRegex
methodpublicfileDeleteByWildcard(  $wildcard ) : void
inherited

Delete files matching given wildcard.

Inherited from: \eZFSFileHandler::fileDeleteByWildcard()

Note that this method is faster than fileDeleteByRegex().

\public \static \sa fileDeleteByRegex()

Parameters
Name Type Description
$wildcard
methodpublicfileDeleteLocal(  $path ) : void
inherited

Deletes a file that has been fetched before.

Inherited from: \eZFSFileHandler::fileDeleteLocal()
Parameters
Name Type Description
$path
Details
See
\fetchUnique  
methodpublicfileExists(  $path ) : void
inherited

Check if given file/dir exists.

Inherited from: \eZFSFileHandler::fileExists()

\public \static

Parameters
Name Type Description
$path
methodpublicfileFetch(  $filePath ) : void
inherited

Fetches file from db and saves it in FS under the same name.

Inherited from: \eZFSFileHandler::fileFetch()

In case of fetching from filesystem does nothing.

Parameters
Name Type Description
$filePath
methodpublicfileFetchContents(  $filePath ) : string | false
inherited

Returns file contents.

Inherited from: \eZFSFileHandler::fileFetchContents()
Parameters
Name Type Description
$filePath
Returns
Type Description
string | false contents string, or false in case of an error.
methodpublicfileLinkCopy(  $srcPath,  $dstPath,  $symLink ) : void
inherited

Create symbolic or hard link to file.

Inherited from: \eZFSFileHandler::fileLinkCopy()

\public \static

Parameters
Name Type Description
$srcPath
$dstPath
$symLink
methodpublicfileMove(  $srcPath,  $dstPath ) : void
inherited

Move file.

Inherited from: \eZFSFileHandler::fileMove()

\public \static

Parameters
Name Type Description
$srcPath
$dstPath
methodpublicfileStore( string $filePath, string $scope = false, string $delete = false,  $datatype = false ) : void
inherited

Store file.

Inherited from: \eZFSFileHandler::fileStore()

In case of storing to filesystem does nothing.

Parameters
Name Type Description
$filePath string

Path to the file being stored.

$scope string

Means something like "file category". May be used to clean caches of a certain type.

$delete string

true if the file should be deleted after storing.

$datatype
methodpublicfileStoreContents(  $filePath,  $contents,  $scope = false,  $datatype = false ) : void
inherited

Store file contents.

Inherited from: \eZFSFileHandler::fileStoreContents()

\public \static

Parameters
Name Type Description
$filePath
$contents
$scope
$datatype
methodpublicisExpired( int $expiry, int $curtime, int $ttl ) : bool
inherited

Calculates if the current file data is expired or not.

Inherited from: \eZFSFileHandler::isExpired()
Parameters
Name Type Description
$expiry int

Time when file is to be expired, a value of -1 will disable this check.

$curtime int

The current time to check against.

$ttl int

Number of seconds the data can live, set to null to disable TTL.

Returns
Type Description
bool
methodpublicisFileExpired( string $fname, int $mtime, int $expiry, int $curtime, int $ttl ) : bool
staticinherited

Calculates if the file data is expired or not.

Inherited from: \eZFSFileHandler::isFileExpired()
Parameters
Name Type Description
$fname string

Name of file, available for easy debugging.

$mtime int

Modification time of file, can be set to false if file does not exist.

$expiry int

Time when file is to be expired, a value of -1 will disable this check.

$curtime int

The current time to check against.

$ttl int

Number of seconds the data can live, set to null to disable TTL.

Returns
Type Description
bool
methodpublicloadMetaData(  $force = false ) : void
inherited

Inherited from: \eZFSFileHandler::loadMetaData()
Parameters
Name Type Description
$force
methodpublicmove(  $dstPath ) : void
inherited

Move file.

Inherited from: \eZFSFileHandler::move()

\public

Parameters
Name Type Description
$dstPath
methodpublicmtime( ) : void
inherited

Returns file modification time.

Inherited from: \eZFSFileHandler::mtime()

\public

methodpublicname( ) : void
inherited

Returns file name.

Inherited from: \eZFSFileHandler::name()

\public

methodpublicpassthrough( int $offset = 0, int $length = false ) : void
inherited

Outputs file contents to the browser Note: does not handle headers. eZFile::downloadHeaders() can be used for this

Inherited from: \eZFSFileHandler::passthrough()
Parameters
Name Type Description
$offset int

Transfer start offset

$length int

Transfer length, in bytes

methodpublicprocessCache( mixed $retrieveCallback, mixed $generateCallback = null, int $ttl = null, int $expiry = null, array $extraData = null ) : void

Creates a single transaction out of the typical file operations for accessing caches.

Caches are normally ready from the database or local file, if the entry does not exist or is expired then it generates the new cache data and stores it. This method takes care of these operations and handles the custom code by performing callbacks when needed.

The $retrieveCallback is used when the file contents can be used (ie. not re-generation) and is called when the file is ready locally. The function will be called with the file path as the first parameter, the mtime as the second and optionally $extraData as the third. The function must return the file contents or an instance of eZClusterFileFailure which can be used to tell the system that the retrieve data cannot be used after all. $retrieveCallback can be set to null which makes the system go directly to the generation.

The $generateCallback is used when the file content is expired or does not exist, in this case the content must be re-generated and stored. The function will be called with the file path as the first parameter and optionally $extraData as the second. The function must return an array with information on the contents, the array consists of: - scope - The current scope of the file, is optional. - datatype - The current datatype of the file, is optional. - content - The file content, this can be any type except null. - binarydata - The binary data which is written to the file. - store - Whether content or binarydata should be stored to the file, if false it will simply return the data. Optional, by default it is true. Note: Set $generateCallback to false to disable generation callback. Note: Set $generateCallback to null to tell the function to perform a write lock but not do any generation, the generation must done be done by the caller by calling storeCache().

Either content or binarydata must be supplied, if not an error is issued and it returns null. If content is set it will be used as the return value of this function, if not it will return the binary data. If binarydata is set it will be used as the binary data for the file, if not it will perform a var_export on content and use that as the binary data.

For convenience the $generateCallback function can return a string which will be considered as the binary data for the file and returned as the content.

For controlling how long a cache entry can be used the parameters $expiry and $ttl is used. $expiry can be set to a timestamp which controls the absolute max time for the cache, after this time/date the cache will never be used. If the value is set to a negative value or null there the expiration check is disabled.

$ttl (time to live) tells how many seconds the cache can live from the time it was stored. If the value is set to negative or null there is no limit for the lifetime of the cache. A value of 0 means that the cache will always expire and practically disables caching. For the cache to be used both the $expiry and $ttl check must hold.

Parameters
Name Type Description
$retrieveCallback mixed
$generateCallback mixed
$ttl int
$expiry int
$extraData array
methodpublicprocessFile(  $callback,  $expiry = false,  $extraData = null ) : void
inherited

Inherited from: \eZFSFileHandler::processFile()
Parameters
Name Type Description
$callback
$expiry
$extraData
methodpublicpurge(  $printCallback = false,  $microsleep = false,  $max = false,  $expiry = false ) : void

Purge local and remote file data for current file.

Parameters
Name Type Description
$printCallback
$microsleep
$max
$expiry
methodprivateremainingCacheGenerationTime( string $filePath ) : int

Returns the remaining time, in seconds, before the generating file times out

Parameters
Name Type Description
$filePath string
Returns
Type Description
int Remaining generation seconds. A negative value indicates a timeout.
methodpublicrequiresBinaryPurge( ) : bool

eZFS2 doesn't require purge as it already purges files in realtime (FS based)

Files are stored on plain FS and removed using FS functions

Returns
Type Description
bool
Details
Deprecated
Deprecated as of 4.5, use {@link eZFS2FileHandler::requiresPurge()} instead.  
Since
4.3  
methodpublicrequiresClusterizing( ) : bool

eZFS2 doesn't require clusterizing, as it only uses the filesystem

Returns
Type Description
bool
methodpublicrequiresPurge( ) : bool

eZFS2 doesn't require purge as it already purges files in realtime (FS based)

Files are stored on plain FS and removed using FS functions

Returns
Type Description
bool
Details
Since
4.5.0  
methodpublicsize( ) : void
inherited

Returns file size.

Inherited from: \eZFSFileHandler::size()

\public

methodpublicstartCacheGeneration( ) : mixed

Starts cache generation for the current file.

This is done by creating a file named by the original file name, prefixed with '.generating'.

Returns
Type Description
mixed true if generation lock was granted, an integer matching the time before the current generation times out
Details
Todo
add timeout handling...  
methodpublicstat( ) : void
inherited

Returns file metadata.

Inherited from: \eZFSFileHandler::stat()

\public

methodpublicstoreCache(  $fileData,  $storeCache = true ) : void

Stores the data in $fileData to the remote and local file and commits the transaction.

The parameter $fileData must contain the same as information as the $generateCallback returns as explained in processCache().

Parameters
Name Type Description
$fileData
$storeCache
Details
Note
This method is just a continuation of the code in processCache() and is not meant to be called alone since it relies on specific state in the database.  
methodpublicstoreContents( string $contents, string $scope = false, string $datatype = false, bool $storeLocally = false ) : void
inherited

Store file contents to disk

Inherited from: \eZFSFileHandler::storeContents()
Parameters
Name Type Description
$contents string

Binary file data

$scope string

Not used in the FS handler

$datatype string

Not used in the FS handler

$storeLocally bool

Not used in the FS handler

Documentation was generated by DocBlox 0.18.1.