Skip to content

LSPHP Options

There are multiple different configuration options that LSPHP can use depending on the setup. There are directives which are meant to be used when configuring Apache configurations and there are environment variables which are used inside of LiteSpeed Web Server specifically.


Directives are meant to be used when using LiteSpeed Web Server with Apache configurations. These directives can be used at either the Server or Virtual Host level.


Apache will not understand LiteSpeed-specific directives, and may fail to start when switching between LiteSpeed Web Server and Apache. For this reason, we recommend wrapping all LiteSpeed-specific directives in <IfModule LiteSpeed></IfModule LiteSpeed> tags. This will essentially disable these directives for Apache and enable them for LiteSpeed Web Server.


LiteSpeed directives enclosed in <IfModule LiteSpeed>``</IfModule LiteSpeed> tags:

<IfModule LiteSpeed>
LSPHP_ProcessGroup on
LSPHP_Workers 15


The LSPHP_Workers directive controls the maximum number of worker/child processes per account in a shared hosting environment. This directive can allow you to set a higher concurrency for certain Virtual Hosts on your shared hosting environment.


The LSPHP_ProcessGroup directive turns ProcessGroup mode on and off when using Apache configuration files. By default this is turned on.


The LSPHP_MaxWaitQ directive sets the maximum number of processes that can be in the PHP external application wait queue. When this limit is reached, new requests will return a 508 “Resource Limit Reached” error. This is the same WaitQ that can be monitored inside the WebAdmin Console under Actions > Real-Time Stats.


Variables are meant to be used when settings need to be set globally on LiteSpeed Web Server. These can be set in the PHP section of LiteSpeed Web Server under Environment.


Default Value: 35


LSAPI_CHILDREN can also be referenced as PHP_LSAPI_CHILDREN.

PHP LSAPI allows a variety of process modes. Two of these modes, Worker and ProcessGroup, can be set using this environment variable.

Setting LSAPI_CHILDREN to 1 puts LSWS in Worker mode. In Worker mode, LiteSpeed Web Server dynamically spawns new PHP processes as they are needed, and kills them when the need has passed.

Setting LSAPI_CHILDREN to a number larger than 1 puts LSWS in ProcessGroup mode. In ProcessGroup mode, the web server will start one PHP parent process that is constantly running. This process will then fork child PHP processes (as opposed to spawning new processes) as they are needed. The number of these child processes that may be created is contolled by the value you set for LSAPI_CHILDREN.

ProcessGroup mode is generally preferred because all PHP processes can then share one memory block for opcode caching.


In Worker mode, an external application's Instances and Max Connections values should be the same. You can find both of these settings in the WebAdmin Console under Configuration > External App > your_external_application.

In ProcessGroup mode, Instances should be set to 1 and Max Connections should match the value of LSAPI_CHILDREN.


Default Value: 0

The LSAPI_AVOID_FORK environment variable specifies whether the internal process manager in ProcessGroup mode should try to avoid forking new child processes.

When set to 0, the internal process manager will not try to avoid forking new processes. To save system resources, it will stop processes when they finish and only start child processes when they are needed. This is often preferred in shared hosting.

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 because it may be faster to recycle existing processes, even if it means sometimes running unused processes.


LSAPI_AVOID_FORK=1 will only keep the child processes alive if there is enough available memory. By default "enough" is set to 1GB, so if your server has less than 1 GB available, setting LSAPI_AVOID_FORK=1 will not work. Instead you can set a limit, as in LSAPI_AVOID_FORK=100M. This will allow the LSAPI_AVOID_FORK variable to work as expected.


Default Values:

  • If LSAPI_AVOID_FORK is set to 1: 0

In ProcessGroup mode, the LSAPI_EXTRA_CHILDREN environment variable 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.


Default Value: 10000


LSAPI_MAX_REQS can also be referenced as PHP_LSAPI_MAX_REQUESTS.

In ProcessGroup mode, this environment variable controls the number of requests each child process will handle before exiting automatically. Several PHP functions have been identified as having memory leaks. This parameter can help reduce memory usage by leaky PHP functions.


Default Value: 300 seconds

In ProcessGroup mode, LSAPI_MAX_IDLE controls how long an idle child process will wait for a new request before it exits. This option helps release system resources taken by idle processes.


Default Values:


In ProcessGroup 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.


Default Value: 3600 seconds

The LSAPI_MAX_PROCESS_TIME environment variable controls the total time that a PHP process can spend processing a request. It is only effective in ProcessGroup or Daemon mode. The parent process will kill child processes spending more time than this threshold.

In ProcessGroup 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 frame, it will be killed by the parent process. This option can help get rid of dead or runaway child processes.


Default Value: FOREVER

In ProcessGroup mode, the LSAPI_PGRP_MAX_IDLE environment variable controls how long the parent process will wait before exiting when there are no child processes running. This option can help release system resources taken up by an idle parent process. This environment variable has the same function as the the Max Idle Time setting in the WebAdmin Console under Configuration > External App > your_external_application.


Default Value: 0

By default, an LSAPI external application will exit automatically when 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 certain situations, such as when an LSAPI process was started manually from the command line.

Adding the LSAPI_PPID_NO_CHECK environment variable and setting it to 1 will disable the check for the existence of a parent process. To turn this setting off, remove the environment variable completely. When PHP is started from the command line using the -b option, this check is disabled automatically.


Default Value: 0

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 to 1, 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.


Default Value: 0

By default, an LSAPI application will send back a notification packet whenever a request has been received. It can be changed to only notify the server for newly established connections by setting this environment variable to 1. This is recommended as a way to gain performance in LiteSpeed Web Server.


Default Value: 0

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.


Default Value:

  • If PHP Version is greater than 5.6: 1
  • If PHP Version is 5.6 or lower: 0

Available as of PHP LSAPI v7.6, the LSAPI_CLEAN_SHUTDOWN environment variable can be used to instruct LSPHP to automatically perform a clean shutdown. A clean shutdown refers to performing cleanup after a PHP crash or abnormal exit (such as manually killing the process). Setting LSAPI_CLEAN_SHUTDOWN to 0 will disable the clean shutdown feature while setting LSAPI_CLEAN_SHUTDOWN to 1 will enable it.


As of LiteSpeed Web Server v6.0.12 build 2, the external application environment variable LS_OOM_SCORE_ADJ can be used to apply oom_score_adj values for PHP processes, independent of the value set for the parent LSWS process. The assigned value will be applied to external applications that are started by the web server.

Usage: LS_OOM_SCORE_ADJ=<desired_value> where "desired_value" is an integer in the -1000 to 1000 range. The lower the value, the lower the chance that the process will be killed.

To illustrate why you might want to use this, let's look at a common scenario:

Your server becomes low on free memory and an OOM killer is invoked. You want to ensure that processes are sacrificed according to importance, so you have set oom_score_adj accordingly. The problem is that setting oom_score_adj for the litespeed process also sets this for litespeed's children, including lsphp processes. While it's highly desirable that LiteSpeed Web Server is protected from an OOM killer, it is conversely desirable that lsphp processes are sacrificed to free up memory.

In this scenario, you use oom_score_adj to set the priority for the litespeed process as usual. In your WebAdmin Console, add the LS_OOM_SCORE_ADJ environment variable to the PHP tab. You may also choose to add the variable to the configuration for a dedicated individual PHP application, if it should have a different priority than PHP in general.


When using top or ps to view PHP scripts being run via LiteSpeed, the paths to the PHP scripts may be truncated at the front, for example:


The beginning of the full path is truncated, but there is a setting to make LiteSpeed show the full path, like so:


To see the full path, add LSAPI_MAX_CMD_SCRIPT_PATH_LEN=80 to the environment variables under the PHP tab, or to your external applications, whichever is applicable.

The maximum value is 255, and the default is 46.


High values may cause PHP to crash.

You will need to restart PHP to apply the change, and you can do so with the pkill lsphp command.

Last update: February 9, 2024