Most PHP LSAPI configurations are found in the WebAdmin console (WebAdmin console > Configuration > External App). PHP LSAPI applications can be further configured using the environment variables listed below:
There are two ways to let PHP handle multiple requests concurrently, server managed mode and self managed mode. In server managed mode, LiteSpeed Web Server dynamically spawns/stops PHP processes. In this mode, an external application's “Instances” setting should match the “Max Connections” configuration. To start PHP in self managed mode, “Instances” should be set to “1”, while the “LSAPI_CHILDREN” environment variable should be >1 and set to match the value of “Max Connections”. In this mode the web server will start one PHP process, and this process will start/stop child PHP processes dynamically based on on demand. Self managed mode is preferred because all PHP processes can then share one memory block for opcode caching. If “LSAPI_CHILDREN” <=1, PHP will be started in server managed mode. Usually, there is no need to set the value of “LSAPI_CHILDREN” over “100”.
“LSAPI_AVOID_FORK” specifies the policy of the internal process manager in self managed mode. When set to “0”, the internal process manager will stop and start child processes on demand to save system resources. This is preferred in a shared hosting environment. When set to “1”, the internal process manager will try to avoid frequently stopping and starting child processes. This might be preferred in a dedicated hosting environment.
(default=1/3 of LSAPI_CHILDREN or 0)
“LSAPI_EXTRA_CHILDREN” controls the maximum number of extra child processes that can be started when existing child processes are malfunctioning. The total number of child processes will be reduced to the level set in “LSAPI_CHILDREN” as soon as service is back to normal. When “LSAPI_AVOID_FORK” is set to “0”, the default value of “LSAPI_EXTRA_CHILDREN” is 1/3 of “LSAPI_CHIDLREN”. When “LSAPI_AVOID_FORK” is set to “1”, the default value is “0”.
This controls how many requests each child process will handle before it exits automatically. Several PHP functions have been identified as having memory leaks. This parameter can help reduce memory usage by leaky PHP functions.
In self managed mode, “LSAPI_MAX_IDLE” controls how long a idle child process will wait for a new request before it exits. This option helps release system resources taken by idle processes.
(default=1/3 of LSAPI_CHILDREN or LSAPI_CHILDREN)
In self managed mode, “LSAPI_MAX_IDLE_CHILDREN” controls how many idle child processes are allowed. Extra idle child processes will be killed by the parent process immediately. When “LSAPI_AVOID_FORK” is set to “0”, the default value of “LSAPI_MAX_IDLE_CHILDREN” is 1/3 of “LSAPI_CHIDLREN”. When “LSAPI_AVOID_FORK” is set to “1”, the default value of “LSAPI_MAX_IDLE_CHILDREN” is the same as the value of “LSAPI_CHILDREN”.
In self managed mode, “LSAPI_MAX_PROCESS_TIME” controls the maximum processing time allowed when processing a request. If a child process can not finish processing a request in the given time period, it will be killed by the parent process. This option can help get rid of dead or runaway child processes.
In self managed mode, “LSAPI_PGRP_MAX_IDLE” controls how long the parent process will wait before exiting when there are no child processes. This option can help release system resources taken up by an idle parent process.
By default, an LSAPI external application will exit automatically if the parent process dies. This is to reduce orphan processes when the web server is restarted. However, it may be desirable to disable this feature in situations such as when an LSAPI process was started manually from the command line. Adding the “LSAPI_PPID_NO_CHECK” environment variable (set it to “1”) will disable the checking for the existence of a parent process. To turn off this setting, remove the environment variable completely. When PHP is started using the ”-b” option, checking is disabled automatically.
By default, an LSAPI application will not leave a core dump file when it crashes. If you want to have LSPHP dump a core file, you should add this environment variable and set to “1”. If set, core files will be created under the current working directory, generally the directory of the PHP script that crashed. To turn off this setting, remove the environment variable completely.
By default, an LSAPI application will send back a notification packet whenever a request has been received. Since PHP LSAPI 5.0, it can be changed to only notify the server for newly established connections by setting this environment variable to “1”. It is recommended as a way to gain performance in LiteSpeed Web Server 4.1 and later.
If set to a non-zero number, LiteSpeed Web Server will log requests into an error log file if a request takes longer than the specified number of milliseconds. This can help identify scripts that are slowing down your server.