Controlling PHP Max Concurrency

The PHP Max Connection setting is controlled by different configurations depending upon whether or not you're using PHP SuEXEC mode.

If the PHP suEXEC setting under Configuration > Server > General > Using Apache Configuration File > PHP suEXEC is set to Yes or User's Home Directory Only, then you are using SuEXEC, otherwise you are not using SuEXEC.

When PHP SuEXEC is used, PHP SuEXEC Max Conn will be used to control the PHP Max Concurrency. LiteSpeed Web Server has a number of PHP setups which offer different ways to control the amount of PHP tasks that can be processed at once in PHP SuEXEC mode.

If PHP SuEXEC mode is not used, the External Application LSAPI Max Connections setting will control the PHP Max Concurrency.

This wiki will go over the ways to control concurrency with different PHP LSAPI setups.

PHP suEXEC Max Connections

LSWS offers three different PHP suEXEC modes: Worker, Daemon, and ProcessGroup.

In suEXEC PHP, LSWS allows you to control the number of PHP processes per user.

  1. Worker: Concurrency is controlled by the PHP suEXEC Max Conn setting Configuration > Server > General > PHP suEXEC Max Conn. This controls the number of PHP processes allowed per user.
  2. Daemon: Same as above. Concurrency is controlled by the PHP suEXEC Max Conn setting Configuration > Server > General > PHP suEXEC Max Conn. This controls the number of PHP processes allowed per user.
  3. ProcessGroup: The PHP suEXEC Max Conn setting sets the default concurrency setting.

PHP suEXEC Max Connections can be customized/overridden at vhost/account level with the LSPHP_Workers directive in an Apache configuration file for all three modes:ProcessGroup, Daemon, and Worker.

For example, 40 has been set through PHP suEXEC Max Conn setting in web admin console, but you would like to set a little higher as 100 for a particular user/account, add the following to the user/account's Apache vhost configuration to override the above setting:

<IfModule LiteSpeed>
  LSPHP_Workers 100
</IfModule>

PHP Non-suEXEC Max Connections

LSWS offers two non-suEXEC PHP modes: Worker and ProcessGroup.

In non-suEXEC modes, there is only one PHP user. PHP concurrency is thus controlled by the the number of connections allowed between LSWS and the PHP engine: the External Application Max Connections setting Configuration > Server > External App > your_external_application.

One must make sure that your external application is also supplied with enough processes to serve these connections. The number of processes should always be set to be equal the Max Connections. This is set differently depending on your PHP mode:

  1. Worker: Simply set the Instances setting Configuration > Server > External App > your_external_application.
  2. ProcessGroup: In ProcessGroup, the Instances setting must be set to 1. Control the number of processes instead with the PHP_LSAPI_CHILDREN environment variable.

Which setup am I using?

Some users may be confused about which setup they are using. Follow the steps in the Which PHP setup am I using? wiki to figure it out.

Reached max children process limit?

You might have already fine-tuned the environment variables such as LSAPI_CHILDREN to 50 but still experienced error message like “Reached max children process limit: 15, extra: 5, current: 20, please increase LSAPI_CHILDREN”. <env>LSAPI_CHILDREN=50</env> has been double-checked in lsphp5 external app and seems no problem. Why doesn't match? What happened? How to fix it?

In PHP suEXEC ProcessGroup mode, “increase LSAPI_CHILDREN” means increase PHP SuEXEC Max Conn setting, not “LSAPI_CHILDREN” setting in php external app setting. Please be aware that it is a global setting applied to all virtual hosts hence you may want to increase PHP processes for only one virtual host Increasing LSPHP_Workers can increase the limit, such as explained in this wiki:

<IfModule LiteSpeed>
LSPHP_Workers 100
</IfModule>

Another environment variable can be used to control the total limit, LSAPI_EXTRA_CHILDREN, which is set to “5” for lsphp5 external app. It won't be overridden. So you will get total limit of 15 + 5 = 20.

Increasing “LSAPI_CHILDREN” will allow more foreground PHP processes running. Increase “LSAPI_EXTRA_CHILDREN” will allow more background PHP processes running.

More details configuration can be found: https://www.litespeedtech.com/docs/litespeed-sapi/php-lsapi/configuration

On the other hand, you should verify if it is normal to have so many PHP processes. You may try to enable cache to avoid such high PHP processes.

 
litespeed_wiki/php/concurrency.txt · Last modified: 2018/09/19 18:43 by Michael Alegre