kernel/private/classes/clusterfilehandlers/ezfs2filehandler.php
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
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

EXPIRY_TIMESTAMP
= 233366400
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- Inherited_from
- \eZFSFileHandler::EXPIRY_TIMESTAMP
Properties


string|null
$cacheType= 'null'
Cached value of cache type
null
Details- Type
- string | null


$filePath= ''
- Type
- n/a
- Inherited_from
- \eZFSFileHandler::$$filePath


int
$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
false
Details- Type
- int


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


$metaData= 'null'
null
Details- Type
- n/a
- Inherited_from
- \eZFSFileHandler::$$metaData


$nonExistantStaleCacheHandling= ''
Holds the preferences used when stale cache is activated and no expired file is available.
This is loaded from file.ini, ClusteringSettings.NonExistantStaleCacheHandling
- Type
- n/a


$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
null
Details- Type
- n/a


int
$remainingCacheGenerationTime= 'false'
Holds the number of seconds remaining before the generating cache times out
false
Details- Type
- int
Methods


_cacheType(
)
:
string
Determines the cache type based on the path
Type | Description |
---|---|
string | viewcache, cacheblock or misc |


_exclusiveLock(
$fname
=
false
)
:
void
Name | Type | Description |
---|---|---|
$fname |


_expire(
string $path
)
:
bool
Expire the given file
Name | Type | Description |
---|---|---|
$path | string | Path of the file to expire |
Type | Description |
---|---|
bool |


_freeExclusiveLock(
$fname
=
false
)
:
void
Name | Type | Description |
---|---|---|
$fname |


_recursiveExpire(
string $directory
)
:
void
Expires all files in a directory
Name | Type | Description |
---|---|---|
$directory | string |


abortCacheGeneration(
)
:
void
Aborts the current cache generation process.
Does so by rolling back the current transaction, which should be the .generating file lock


checkCacheGenerationTimeout(
)
:
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


delete(
)
:
void
Deletes specified file/directory.
If a directory specified it is deleted recursively.
\public \static


deleteLocal(
)
:
void
Deletes a file that has been fetched before.
In case of fetching from filesystem does nothing.
\public


eZFSFileHandler(
$filePath
=
false
)
:
void
$filePath File path. If specified, file metadata is fetched in the constructor.
Name | Type | Description |
---|---|---|
$filePath |


endCacheGeneration(
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.
Name | Type | Description |
---|---|---|
$rename | bool | Rename (true) or delete (false) the generating file |
Type | Description |
---|---|
bool |


exists(
)
:
void
NOTE: this function does not interact with filesystem. Instead, it just returns existance status determined in the constructor.
\public


fetch(
$noLocalCache
=
false
)
:
void
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.
Name | Type | Description |
---|---|---|
$noLocalCache |


fetchUnique(
)
:
string
Fetches file from db and saves it in FS under unique name.
Inherited from: \eZFSFileHandler::fetchUnique()In case of fetching from filesystem, does nothing
Type | Description |
---|---|
string | The unique file path. on FS, the file path. |


fileCopy(
$srcPath, $dstPath
)
:
void
\public \static
Name | Type | Description |
---|---|---|
$srcPath | ||
$dstPath |


fileDelete(
\$path $path, \$fnamePart $fnamePart
=
false
)
:
void
Deletes the file(s) or directory matching $path and $fnamePart if given
Name | Type | Description |
---|---|---|
$path | \$path | path of the file to delete |
$fnamePart | \$fnamePart | path of the file to delete |


fileDeleteByDirList(
$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()
Name | Type | Description |
---|---|---|
$dirList | ||
$commonPath | ||
$commonSuffix |


fileDeleteByRegex(
$dir, $fileRegex
)
:
void
Delete files matching regex $fileRegex under directory $dir.
Inherited from: \eZFSFileHandler::fileDeleteByRegex()\public \static \sa fileDeleteByWildcard()
Name | Type | Description |
---|---|---|
$dir | ||
$fileRegex |


fileDeleteByWildcard(
$wildcard
)
:
void
Delete files matching given wildcard.
Inherited from: \eZFSFileHandler::fileDeleteByWildcard()Note that this method is faster than fileDeleteByRegex().
\public \static \sa fileDeleteByRegex()
Name | Type | Description |
---|---|---|
$wildcard |


fileDeleteLocal(
$path
)
:
void
Deletes a file that has been fetched before.
Inherited from: \eZFSFileHandler::fileDeleteLocal()Name | Type | Description |
---|---|---|
$path |
- See
- \fetchUnique


fileFetch(
$filePath
)
:
void
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.
Name | Type | Description |
---|---|---|
$filePath |


fileFetchContents(
$filePath
)
:
string | false
Name | Type | Description |
---|---|---|
$filePath |
Type | Description |
---|---|
string | false | contents string, or false in case of an error. |


fileLinkCopy(
$srcPath, $dstPath, $symLink
)
:
void
\public \static
Name | Type | Description |
---|---|---|
$srcPath | ||
$dstPath | ||
$symLink |


fileMove(
$srcPath, $dstPath
)
:
void
\public \static
Name | Type | Description |
---|---|---|
$srcPath | ||
$dstPath |


fileStore(
string $filePath, string $scope
=
false, string $delete
=
false, $datatype
=
false
)
:
void
In case of storing to filesystem does nothing.
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 |


fileStoreContents(
$filePath, $contents, $scope
=
false, $datatype
=
false
)
:
void
\public \static
Name | Type | Description |
---|---|---|
$filePath | ||
$contents | ||
$scope | ||
$datatype |


isExpired(
int $expiry, int $curtime, int $ttl
)
:
bool
Calculates if the current file data is expired or not.
Inherited from: \eZFSFileHandler::isExpired()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. |
Type | Description |
---|---|
bool |


isFileExpired(
string $fname, int $mtime, int $expiry, int $curtime, int $ttl
)
:
bool
Calculates if the file data is expired or not.
Inherited from: \eZFSFileHandler::isFileExpired()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. |
Type | Description |
---|---|
bool |


loadMetaData(
$force
=
false
)
:
void
Name | Type | Description |
---|---|---|
$force |


passthrough(
int $offset
=
0, int $length
=
false
)
:
void
Outputs file contents to the browser Note: does not handle headers. eZFile::downloadHeaders() can be used for this
Inherited from: \eZFSFileHandler::passthrough()Name | Type | Description |
---|---|---|
$offset | int | Transfer start offset |
$length | int | Transfer length, in bytes |


processCache(
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.
Name | Type | Description |
---|---|---|
$retrieveCallback | mixed | |
$generateCallback | mixed | |
$ttl | int | |
$expiry | int | |
$extraData | array |


processFile(
$callback, $expiry
=
false, $extraData
=
null
)
:
void
Name | Type | Description |
---|---|---|
$callback | ||
$expiry | ||
$extraData |


purge(
$printCallback
=
false, $microsleep
=
false, $max
=
false, $expiry
=
false
)
:
void
Purge local and remote file data for current file.
Name | Type | Description |
---|---|---|
$printCallback | ||
$microsleep | ||
$max | ||
$expiry |


remainingCacheGenerationTime(
string $filePath
)
:
int
Returns the remaining time, in seconds, before the generating file times out
Name | Type | Description |
---|---|---|
$filePath | string |
Type | Description |
---|---|
int | Remaining generation seconds. A negative value indicates a timeout. |


requiresBinaryPurge(
)
:
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
Type | Description |
---|---|
bool |
- Deprecated
- Deprecated as of 4.5, use {@link eZFS2FileHandler::requiresPurge()} instead.
- Since
- 4.3


requiresClusterizing(
)
:
bool
eZFS2 doesn't require clusterizing, as it only uses the filesystem
Type | Description |
---|---|
bool |


requiresPurge(
)
:
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
Type | Description |
---|---|
bool |
- Since
- 4.5.0


startCacheGeneration(
)
:
mixed
Starts cache generation for the current file.
This is done by creating a file named by the original file name, prefixed with '.generating'.
Type | Description |
---|---|
mixed | true if generation lock was granted, an integer matching the time before the current generation times out |
- Todo
- add timeout handling...


storeCache(
$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().
Name | Type | Description |
---|---|---|
$fileData | ||
$storeCache |
- 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.


storeContents(
string $contents, string $scope
=
false, string $datatype
=
false, bool $storeLocally
=
false
)
:
void
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 |