Sapi
in package
Server Application Programming Interface.
This file handles all interaction between the application (SMF) and the server.
Not all APIs have are functional on all server interfaces. If this is the case the API call will do nothing.
Some functions may not be defined or definable in the documentation as they are bundled by 3rd party processes, such as apache_* functions. To suppress IDE warnings, we use 'suppress PHP0417'.
Table of Contents
Constants
- OS_LINUX = 'Linux'
- OS_MAC = 'Darwin'
- OS_WINDOWS = 'Windows'
- SERVER_APACHE = 'apache'
- SERVER_IIS = 'iis'
- SERVER_LIGHTTPD = 'lighttpd'
- SERVER_LITESPEED = 'litespeed'
- SERVER_NGINX = 'nginx'
Properties
- $server_software : array<string|int, mixed>
Methods
- getTempDir() : string
- Locates the most appropriate temporary directory.
- httpsOn() : bool
- Check if the connection is using HTTPS.
- isCGI() : bool
- Checks If we are running a CGI instance.
- isCLI() : bool
- Checks If we are running a CLI (shell/cron) instance.
- isOS() : bool
- Checks if the server is running a specific operating system.
- isSoftware() : bool
- Checks if the server is running a specific server software.
- load() : void
- (Re)initializes some $context values that need to be set dynamically.
- memoryReturnBytes() : int
- Helper function to convert memory string settings to bytes
- needsLoginFix() : bool
- A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
- resetTimeout() : mixed
- Makes call to the Server API (SAPI) to reset the timeout.
- setMemoryLimit() : bool
- Helper function to set the system memory to a needed value.
- setTimeLimit() : mixed
- Makes call to the Server API (SAPI) to increase the time limit.
- supportsIsoCaseFolding() : bool
- Checks if the server is able to support case folding.
Constants
OS_LINUX
public
mixed
OS_LINUX
= 'Linux'
OS_MAC
public
mixed
OS_MAC
= 'Darwin'
OS_WINDOWS
public
mixed
OS_WINDOWS
= 'Windows'
SERVER_APACHE
public
mixed
SERVER_APACHE
= 'apache'
SERVER_IIS
public
mixed
SERVER_IIS
= 'iis'
SERVER_LIGHTTPD
public
mixed
SERVER_LIGHTTPD
= 'lighttpd'
SERVER_LITESPEED
public
mixed
SERVER_LITESPEED
= 'litespeed'
SERVER_NGINX
public
mixed
SERVER_NGINX
= 'nginx'
Properties
$server_software
protected
array<string|int, mixed>
$server_software
= [self::SERVER_IIS => 'Microsoft-IIS', self::SERVER_APACHE => 'Apache', self::SERVER_LITESPEED => 'LiteSpeed', self::SERVER_LIGHTTPD => 'lighttpd', self::SERVER_NGINX => 'nginx']
Server Map.
Methods
getTempDir()
Locates the most appropriate temporary directory.
public
static getTempDir() : string
Systems using open_basedir
restrictions may receive errors with
sys_get_temp_dir()
due to misconfigurations on servers. Other
cases sys_temp_dir may not be set to a safe value. Additionally
sys_get_temp_dir
may use a readonly directory. This attempts to
find a working temp directory that is accessible under the
restrictions and is writable to the web service account.
Directories checked against open_basedir
:
sys_get_temp_dir()
upload_tmp_dir
session.save_path
cachedir
Return values
string —Path to a temporary directory.
httpsOn()
Check if the connection is using HTTPS.
public
static httpsOn() : bool
Return values
bool —Whether the connection is using HTTPS.
isCGI()
Checks If we are running a CGI instance.
public
static isCGI() : bool
Return values
bool —True if we are running under CGI, false otherwise.
isCLI()
Checks If we are running a CLI (shell/cron) instance.
public
static isCLI() : bool
Return values
bool —True if we are running under CLI, false otherwise.
isOS()
Checks if the server is running a specific operating system.
public
static isOS(string|array<string|int, string> $os) : bool
Parameters
- $os : string|array<string|int, string>
-
The os as defined in our constants
Return values
bool —True if we are running the requested os, false otherwise.
isSoftware()
Checks if the server is running a specific server software.
public
static isSoftware(string|array<string|int, string> $server) : bool
Parameters
- $server : string|array<string|int, string>
-
The server software as defined in our constants.
Return values
bool —True if we are running the requested software, false otherwise.
load()
(Re)initializes some $context values that need to be set dynamically.
public
static load() : void
memoryReturnBytes()
Helper function to convert memory string settings to bytes
public
static memoryReturnBytes(string $val) : int
Parameters
- $val : string
-
The byte string, like '256M' or '1G'.
Return values
int —The string converted to a proper integer in bytes.
needsLoginFix()
A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
public
static needsLoginFix() : bool
Return values
bool —True if it does, false otherwise
resetTimeout()
Makes call to the Server API (SAPI) to reset the timeout.
public
static resetTimeout() : mixed
Tags
setMemoryLimit()
Helper function to set the system memory to a needed value.
public
static setMemoryLimit(string $needed[, bool $in_use = false ]) : bool
- If the needed memory is greater than current, will attempt to get more.
- If $in_use is set to true, will also try to take the current memory usage in to account.
Parameters
- $needed : string
-
The amount of memory to request. E.g.: '256M'.
- $in_use : bool = false
-
Set to true to account for current memory usage.
Return values
bool —Whether we have the needed amount memory.
setTimeLimit()
Makes call to the Server API (SAPI) to increase the time limit.
public
static setTimeLimit([int $limit = 600 ]) : mixed
Parameters
- $limit : int = 600
-
Requested amount of time, defaults to 600 seconds.
supportsIsoCaseFolding()
Checks if the server is able to support case folding.
public
static supportsIsoCaseFolding() : bool
Tags
Return values
bool —True if it does, false otherwise