CSSystemUtils
in package
Collection of various general convenience methods like Performance Monitoring, Session Handling and Environment Detection
Tags
Table of Contents
- DEFAULT_TIME_LIMIT = 120
- Defines the default value of the maximum execution time limit.
- alert() : void
- This function displays a message window containing arbitrary object types
- checkMemory() : void
- Checks the memory usage and frees some memory if necessary using CS::freeMemory()
- createBackup() : void
- Creates a database backup that can be installed later at the admin/install.php
- deleteOldBackupFiles() : void
- Deletes old Backup Files in the projects data/backup directory
- deleteOldCacheFiles() : void
- Deletes old Cache Files in the projects data/cache directory
- displayBandWidth() : string
- Provides a simple client side speed check towards the server
- error() : void
- This function fires a standard CS error
- executeCommand() : string
- Synchronously executes an external process.
- getAccessKey() : mixed
- Returns a browser dependant Accesskey shortcut
- getApacheVersion() : mixed
- getAvailableMemory() : int
- Returns the available memory in bytes
- getAverageServerLoad() : array<string|int, mixed>
- Returns load on server.
- getBrowser() : array<string|int, mixed>
- Tells the current web browser informations using the php method get_browser()
- getBrowserClient() : string
- Tells the client of the current web browser
- getBrowserName() : string
- Tells the name of the current web browser.
- getBrowserVersion() : string
- Tells the version of the current web browser
- getCPUUsageInPercent() : string
- Returns the CPU Usage in percent
- getEncodedCookie() : mixed
- getFileUploadAllowed() : bool
- Returns PHP ini value of 'file_uploads'.
- getFreeMemory() : int
- Returns the free memory in bytes or as percent of the available memory
- getHostType() : int
- Returns the current system host type.
- getMachineArchitecture() : mixed
- getMajorVersion() : string
- returns the current CONTENTSERV major version, e.g. CS12
- getMinorVersion() : string
- returns the current CONTENTSERV minor version, e.g. CS12.1
- getNumberOfCPUs() : int
- Returns the number of available CPU cores
- getOSLabel() : string
- Returns the "Pretty" name of the server operating system
- getPHPArchitecture() : mixed
- getPhysicalMemory() : float
- Returns physical system memory in bytes.
- getServiceBuildHash() : string
- Retrieves the build hash that the service PIM is running
- getServiceDetails() : array<string|int, mixed>
- Retrieves all information about service available from manifest.json, caching the data retrieved
- getServiceVersion() : string
- Retrieves the version that the service PIM is running
- getSessionID() : string
- returns the current session id
- getSessionLifeTime() : int
- Returns the session lifetime in seconds, assuming a minimum of 300 seconds (the smallest of PingFrequency or session.gc_maxlifetime or session.cookie_lifetime)
- getTimeLimit() : int
- Returns the maximum execution time limit.
- getUploadMaxFiles() : int
- Returns PHP ini value of 'max_file_upload'.
- getUploadMaxFileSize() : int|string
- Determines the max upload file size, defined in PHP INI
- getWebServerArchitecture() : mixed
- getWebServerType() : mixed
- guessAcceptLanguage() : string
- Guesses the language accepted from the client by reading the Accept-Language header
- hideErrorMessages() : the
- Sets the visibility of error messages temporarily while the current script is running
- isApacheWebServer() : mixed
- isChromeBrowser() : bool
- Tells whether the web browser is a Chrome browser
- isDeveloperSystem() : bool
- Tells whether the web server is a developer system
- isEdgeBrowser() : bool
- Tells whether the web browser is a Microsoft Edge Browser
- isFirefoxBrowser() : bool
- Tells whether the web browser is a Firefox browser
- isJavaBridgeInstalled() : bool
- Checks if the Zend JavaBridge Server is installed and enabled on the web server machine.
- isLinuxServer() : bool
- Tells whether the web server runs on linux
- isMacBrowser() : bool
- Tells whether the web browser is on a mac
- isMacServer() : false
- Tells whether the web server runs on mac
- isMSIEBrowser() : bool
- Tells whether the web browser is a Microsoft Internet Explorer
- isOnPremiseSystem() : bool
- Checks if the system is an On-Premise environment.
- isOperaBrowser() : bool
- Tells whether the web browser is Opera
- isPresalesSystem() : bool
- Tells whether the web server is a presales system
- isProductiveSystem() : bool
- Tells whether the web server is a productive system
- isSaasSystem() : bool
- Checks if the system is a SaaS environment.
- isSafariBrowser() : bool
- Tells whether the web browser is a Safari browser
- isTestSystem() : bool
- Tells whether the web server is a test system
- isWinBrowser() : bool
- Tells whether the web browser is on a windows
- isWinServer() : false
- Tells whether the web server runs on windows
- lock() : bool
- This function tries to receive a virtual lock for a given context
- measurePoint() : void
- Adds a measurePoint where the performance can be measured
- measureTime() : void
- Adds a time measurement, where all times for with the same name are summed to see the complete required time
- sessionClose() : void
- performs a session_write_close on the current session and sets the session id to a session closed constant
- sessionGet() : mixed
- Gets the value of a session wide variable previously defined with CSSystemUtils::sessionSet
- sessionSet() : the
- Sets a session wide variable
- sessionStart() : new
- Starts a session
- sessionUse() : mixed
- Registers one variable from the request in the session and in $GLOBALS
- setEncodedCookie() : mixed
- setEnvironment() : bool
- Sets certain environment variables in the server environment.
- setMemoryLimit() : void
- Increases the memory limit. The limit is only changed if the new limit is larger than the older one
- setTimeLimit() : void
- Increases the execution time limit. The limit is only changed if the new limit is larger than the older one
- setUploadMaxFiles() : int
- The maximum number of files allowed to be uploaded simultaneously.
- setUploadMaxFileSize() : void
- Sets (for request) the max upload file size 'post_max_size'.
- showErrorsAsExceptions() : void
- If errors are visible they are thrown as exceptions (TRUE) or as default error dialog (FALSE)
- showErrorsAsPlainText() : void
- If errors are visible they are shown as plain text (TRUE) or as html error dialog (FALSE)
- unlock() : void
- This function unlocks a virtual lock that was provided with the lock method
Constants
DEFAULT_TIME_LIMIT
Defines the default value of the maximum execution time limit.
public
int
DEFAULT_TIME_LIMIT
= 120
Tags
Methods
alert()
This function displays a message window containing arbitrary object types
public
static alert(mixed $mixed[, bool $showTrace = FALSE ]) : void
Parameters
- $mixed : mixed
-
the variable to be displayed, can be object, array, variable and many more
- $showTrace : bool = FALSE
-
if true the message box contains also the call trace
Tags
Return values
void —checkMemory()
Checks the memory usage and frees some memory if necessary using CS::freeMemory()
public
static checkMemory() : void
Tags
Return values
void —createBackup()
Creates a database backup that can be installed later at the admin/install.php
public
static createBackup() : void
Tags
Return values
void —deleteOldBackupFiles()
Deletes old Backup Files in the projects data/backup directory
public
static deleteOldBackupFiles([int $olderThanDays = 30 ]) : void
This function call can be used in external cron jobs, that want to trigger clean up tasks at OS level
Parameters
- $olderThanDays : int = 30
-
all backup files older this number of days are deleted
Tags
Return values
void —deleteOldCacheFiles()
Deletes old Cache Files in the projects data/cache directory
public
static deleteOldCacheFiles([int $olderThanDays = 7 ]) : void
This function call can be used in external cron jobs, that want to trigger clean up tasks at OS level
Parameters
- $olderThanDays : int = 7
-
all cache files older this number of days are deleted
Tags
Return values
void —displayBandWidth()
Provides a simple client side speed check towards the server
public
static displayBandWidth([string $basedOnFile = null ][, string $jsOnAfterDisplay = '' ]) : string
This method renders a span in the browser and downloads a file from the web server through an ajax request. Once the file is downloaded the Megabit per Second are displayed in the span.
Parameters
- $basedOnFile : string = null
-
relative link to the file from the admin directory
- $jsOnAfterDisplay : string = ''
-
optional javascript code that should be evaluated at the end
Tags
Return values
string —HTML code that runs the test and displays it in the browser
error()
This function fires a standard CS error
public
static error(string $message[, string $details = NULL ]) : void
The error handling can include a mail, log entries or error windows, depending on the settings.
Parameters
- $message : string
-
the message of the error
- $details : string = NULL
-
the description of the error
Tags
Return values
void —executeCommand()
Synchronously executes an external process.
public
static executeCommand(string $command[, string $commandDir = '' ][, array<string|int, mixed> $environment = array() ][, int $timeout = 3600 ]) : string
Parameters
- $command : string
-
the command line string of the process
- $commandDir : string = ''
-
the context directory under which the process should be executed
- $environment : array<string|int, mixed> = array()
-
array with additional environment variables that should be available at runtime
- $timeout : int = 3600
-
number of seconds after which the process should be killed
Tags
Return values
string —the return value of the process
getAccessKey()
Returns a browser dependant Accesskey shortcut
public
static getAccessKey(string $key) : mixed
Parameters
- $key : string
-
the character which should be used as Accesskey
Tags
Return values
mixed —getApacheVersion()
public
static getApacheVersion() : mixed
Tags
Return values
mixed —getAvailableMemory()
Returns the available memory in bytes
public
static getAvailableMemory() : int
Tags
Return values
int —getAverageServerLoad()
Returns load on server.
public
static getAverageServerLoad() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getBrowser()
Tells the current web browser informations using the php method get_browser()
public
static getBrowser() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —The current web browser informations
getBrowserClient()
Tells the client of the current web browser
public
static getBrowserClient() : string
Tags
Return values
string —the client of the current web browser
getBrowserName()
Tells the name of the current web browser.
public
static getBrowserName() : string
Tags
Return values
string —the name of the current web browser
getBrowserVersion()
Tells the version of the current web browser
public
static getBrowserVersion() : string
Tags
Return values
string —the version of the current web browser
getCPUUsageInPercent()
Returns the CPU Usage in percent
public
static getCPUUsageInPercent() : string
Tags
Return values
string —CPU Usage in percent
getEncodedCookie()
public
static getEncodedCookie(mixed $cookieType, mixed $name) : mixed
Parameters
- $cookieType : mixed
- $name : mixed
Tags
Return values
mixed —getFileUploadAllowed()
Returns PHP ini value of 'file_uploads'.
public
static getFileUploadAllowed() : bool
Tags
Return values
bool —getFreeMemory()
Returns the free memory in bytes or as percent of the available memory
public
static getFreeMemory([bool $inBytes = TRUE ]) : int
Parameters
- $inBytes : bool = TRUE
-
whether the free memory should be returned in bytes (true) or percent (false)
Tags
Return values
int —the available memory
getHostType()
Returns the current system host type.
public
static getHostType() : int
Possible return values: self::HOST_TYPE_*
Tags
Return values
int —getMachineArchitecture()
public
static getMachineArchitecture() : mixed
Tags
Return values
mixed —getMajorVersion()
returns the current CONTENTSERV major version, e.g. CS12
public
static getMajorVersion() : string
Tags
Return values
string —the current major version
getMinorVersion()
returns the current CONTENTSERV minor version, e.g. CS12.1
public
static getMinorVersion() : string
Tags
Return values
string —the current minor version
getNumberOfCPUs()
Returns the number of available CPU cores
public
static getNumberOfCPUs() : int
Tags
Return values
int —getOSLabel()
Returns the "Pretty" name of the server operating system
public
static getOSLabel() : string
Tags
Return values
string —the os name
getPHPArchitecture()
public
static getPHPArchitecture() : mixed
Tags
Return values
mixed —getPhysicalMemory()
Returns physical system memory in bytes.
public
static getPhysicalMemory() : float
Tags
Return values
float —getServiceBuildHash()
Retrieves the build hash that the service PIM is running
public
static getServiceBuildHash() : string
Tags
Return values
string —The build hash that the service is running, retrieved from manifest.json
getServiceDetails()
Retrieves all information about service available from manifest.json, caching the data retrieved
public
static getServiceDetails() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Associative array of the service PIM data, retrieved from manifest.json, having the following keys:
- "name": service name, i.e., "pim-dam"
- "description": service description text
- "version": version built, released or planned version, based on pipeline rule
- "branch": branch built based on repository reference (branch or tag)
- "build_no": build number, equivalent to pipeline ID
- "build_hash": repository hash against which pipeline is built
- "datetime": date-time (in UTC format) of the pipeline execution time
getServiceVersion()
Retrieves the version that the service PIM is running
public
static getServiceVersion() : string
Tags
Return values
string —The version that the service is running, retrieved from manifest.json
getSessionID()
returns the current session id
public
static getSessionID() : string
Tags
Return values
string —the current session id
getSessionLifeTime()
Returns the session lifetime in seconds, assuming a minimum of 300 seconds (the smallest of PingFrequency or session.gc_maxlifetime or session.cookie_lifetime)
public
static getSessionLifeTime() : int
Tags
Return values
int —Session lifetime in seconds
getTimeLimit()
Returns the maximum execution time limit.
public
static getTimeLimit() : int
If no time limit is set the default value of "120" seconds will be used.
Tags
Return values
int —getUploadMaxFiles()
Returns PHP ini value of 'max_file_upload'.
public
static getUploadMaxFiles() : int
Tags
Return values
int —getUploadMaxFileSize()
Determines the max upload file size, defined in PHP INI
public
static getUploadMaxFileSize(int $iTestMaxFileSize) : int|string
Parameters
- $iTestMaxFileSize : int
-
If set, a check if the given file size is greater that defined.
Tags
Return values
int|string —Returns max file size in bytes
getWebServerArchitecture()
public
static getWebServerArchitecture() : mixed
Tags
Return values
mixed —getWebServerType()
public
static getWebServerType() : mixed
Tags
Return values
mixed —guessAcceptLanguage()
Guesses the language accepted from the client by reading the Accept-Language header
public
static guessAcceptLanguage() : string
Tags
Return values
string —The language short name like en or de. If none of the known languages is found the projects default language is returned.
hideErrorMessages()
Sets the visibility of error messages temporarily while the current script is running
public
static hideErrorMessages([mixed $visible = FALSE ]) : the
Parameters
- $visible : mixed = FALSE
Tags
Return values
the —error message visibility before the call
isApacheWebServer()
public
static isApacheWebServer() : mixed
Tags
Return values
mixed —isChromeBrowser()
Tells whether the web browser is a Chrome browser
public
static isChromeBrowser() : bool
Tags
Return values
bool —true if the web client runs on Chrome
isDeveloperSystem()
Tells whether the web server is a developer system
public
static isDeveloperSystem() : bool
Tags
Return values
bool —true if the web server is a developer system
isEdgeBrowser()
Tells whether the web browser is a Microsoft Edge Browser
public
static isEdgeBrowser() : bool
Tags
Return values
bool —true if the web client runs on Microsoft Edge
isFirefoxBrowser()
Tells whether the web browser is a Firefox browser
public
static isFirefoxBrowser() : bool
Tags
Return values
bool —true if the web client runs on Firefox
isJavaBridgeInstalled()
Checks if the Zend JavaBridge Server is installed and enabled on the web server machine.
public
static isJavaBridgeInstalled() : bool
This check should always be performed prior to creating objects via the "new Java(...)" statement. If you try to instantiate Java objects without the JBS being installed, this will result in a fatal error, which instantly leads to the termination of your script.
Tags
Return values
bool —isLinuxServer()
Tells whether the web server runs on linux
public
static isLinuxServer() : bool
Tags
Return values
bool —true if the web server runs on linux
isMacBrowser()
Tells whether the web browser is on a mac
public
static isMacBrowser() : bool
Tags
Return values
bool —true if the web client runs on a mac
isMacServer()
Tells whether the web server runs on mac
public
static isMacServer() : false
Tags
Return values
false —isMSIEBrowser()
Tells whether the web browser is a Microsoft Internet Explorer
public
static isMSIEBrowser([int $iMinVersion = NULL ][, int $iMaxVersion = NULL ]) : bool
Parameters
- $iMinVersion : int = NULL
-
the minimum allowed version of the MSIE
- $iMaxVersion : int = NULL
-
the maximum allowed version of the MSIE
Tags
Return values
bool —true if the web client runs on MSIE
isOnPremiseSystem()
Checks if the system is an On-Premise environment.
public
static isOnPremiseSystem() : bool
Tags
Return values
bool —true if the system is an On-Premise environment.
isOperaBrowser()
Tells whether the web browser is Opera
public
static isOperaBrowser() : bool
Tags
Return values
bool —true if the web client runs on Opera
isPresalesSystem()
Tells whether the web server is a presales system
public
static isPresalesSystem() : bool
Tags
Return values
bool —true if the web server is a presales system
isProductiveSystem()
Tells whether the web server is a productive system
public
static isProductiveSystem() : bool
Tags
Return values
bool —true if the web server is a productive system
isSaasSystem()
Checks if the system is a SaaS environment.
public
static isSaasSystem() : bool
Tags
Return values
bool —true if the system is a SaaS environment.
isSafariBrowser()
Tells whether the web browser is a Safari browser
public
static isSafariBrowser() : bool
Tags
Return values
bool —true if the web client runs on Safari
isTestSystem()
Tells whether the web server is a test system
public
static isTestSystem() : bool
Tags
Return values
bool —true if the web server is a test system
isWinBrowser()
Tells whether the web browser is on a windows
public
static isWinBrowser() : bool
Tags
Return values
bool —true if the web client runs on Firefoxs
isWinServer()
Tells whether the web server runs on windows
public
static isWinServer() : false
Tags
Return values
false —lock()
This function tries to receive a virtual lock for a given context
public
static lock(string $lockName[, int $maxWaitingSec = 60 ][, bool $lockForProject = FALSE ][, int $parallelThreadCount = 1 ]) : bool
Locks are important, if you want to be sure, only one script for a certain time frame can access a ressource. To release the lock call the method unlock().
Parameters
- $lockName : string
-
a lock name which defines the ID of the lock.
- $maxWaitingSec : int = 60
-
the maximum amount of seconds which should be waited until the lock returns with failed status.
- $lockForProject : bool = FALSE
-
whether the lock name should be unique for every project or for all projects.
- $parallelThreadCount : int = 1
-
the amount of locks which can be received for the same lock name.
Tags
Return values
bool —whether the lock could be received.
measurePoint()
Adds a measurePoint where the performance can be measured
public
static measurePoint([string $name = "MeasurePoint" ][, string $attributes = "" ][, mixed $folderFlag = NULL ]) : void
Parameters
- $name : string = "MeasurePoint"
-
the name of the measurepoint
- $attributes : string = ""
-
additional attributes.
- $folderFlag : mixed = NULL
-
determines whether following measurepoints are placed within this measurepoint like in folders or not true if the following points should be placed within false if a open folder should be closed - the name and attributes params must be the same like in the open point null if the measurepoint does not contain any submeasurepoints
Tags
Return values
void —measureTime()
Adds a time measurement, where all times for with the same name are summed to see the complete required time
public
static measureTime(string $name[, mixed $open = TRUE ]) : void
Parameters
- $name : string
-
the name of the time measurement
- $open : mixed = TRUE
-
whether it is the start (true) or end (false) point of the measurement
Tags
Return values
void —sessionClose()
performs a session_write_close on the current session and sets the session id to a session closed constant
public
static sessionClose([bool $errorWhenReopeningFailed = TRUE ]) : void
Parameters
- $errorWhenReopeningFailed : bool = TRUE
-
whether an error should be displayed if reopening the session failed as headers have already been send
Tags
Return values
void —sessionGet()
Gets the value of a session wide variable previously defined with CSSystemUtils::sessionSet
public
static sessionGet(string $name) : mixed
Parameters
- $name : string
-
name of the variable
Tags
Return values
mixed —value of the variable
sessionSet()
Sets a session wide variable
public
static sessionSet(string $name, string $value[, mixed $directClose = FALSE ]) : the
Parameters
- $name : string
-
name of the variable
- $value : string
-
value of the variable
- $directClose : mixed = FALSE
Tags
Return values
the —value of the variable after setting it
sessionStart()
Starts a session
public
static sessionStart() : new
Tags
Return values
new —session id
sessionUse()
Registers one variable from the request in the session and in $GLOBALS
public
static sessionUse(string $name[, string $default = '' ][, string $variableType = '' ]) : mixed
Parameters
- $name : string
-
name of the variable
- $default : string = ''
-
default value of the variable
- $variableType : string = ''
-
the optional variable type (get, post, cookie, ...)
Tags
Return values
mixed —value of the variable
setEncodedCookie()
public
static setEncodedCookie(mixed $cookieType, mixed $name, mixed $value) : mixed
Parameters
- $cookieType : mixed
- $name : mixed
- $value : mixed
Tags
Return values
mixed —setEnvironment()
Sets certain environment variables in the server environment.
public
static setEnvironment([array<string|int, mixed> $amEnvironment = array() ]) : bool
The environment variable will only exist for the duration of the current request. At the end of the request, the environment is restored to its original state.
Parameters
- $amEnvironment : array<string|int, mixed> = array()
-
An array containing environment variable key-value pairs, e.g. "array('FOO' => 'BAR')".
Tags
Return values
bool —TRUE, if any environment variables have been set or FALSE, if the $amEnvironment does not contain an array or if the array does not have any entries.
setMemoryLimit()
Increases the memory limit. The limit is only changed if the new limit is larger than the older one
public
static setMemoryLimit(string $iMemoryLimit) : void
Parameters
- $iMemoryLimit : string
-
the new memory limit
Tags
Return values
void —setTimeLimit()
Increases the execution time limit. The limit is only changed if the new limit is larger than the older one
public
static setTimeLimit(int $iLimit) : void
Parameters
- $iLimit : int
-
the new time limit
Tags
Return values
void —setUploadMaxFiles()
The maximum number of files allowed to be uploaded simultaneously.
public
setUploadMaxFiles(int $iNewValue) : int
Default by PHP is 20.
Parameters
- $iNewValue : int
-
The new value to be set.
Tags
Return values
int —Return the new value.
setUploadMaxFileSize()
Sets (for request) the max upload file size 'post_max_size'.
public
static setUploadMaxFileSize(int $iNewMaxSize) : void
Parameters
- $iNewMaxSize : int
Tags
Return values
void —showErrorsAsExceptions()
If errors are visible they are thrown as exceptions (TRUE) or as default error dialog (FALSE)
public
static showErrorsAsExceptions([mixed $bAsExceptions = TRUE ]) : void
Parameters
- $bAsExceptions : mixed = TRUE
Tags
Return values
void —showErrorsAsPlainText()
If errors are visible they are shown as plain text (TRUE) or as html error dialog (FALSE)
public
static showErrorsAsPlainText([mixed $bAsPlainText = TRUE ]) : void
Parameters
- $bAsPlainText : mixed = TRUE
Tags
Return values
void —unlock()
This function unlocks a virtual lock that was provided with the lock method
public
static unlock(mixed $lockName) : void
Parameters
- $lockName : mixed
