This is an old revision of the document!


PHP Detached Mode in LiteSpeed Web Server

PHP Detached Mode is a big feature available in LSWS 5.3 and later.

In previous versions (LSWS 5.2.x and below), all PHP processes were attached to LiteSpeed Web Server processes. As such, when LiteSpeed Web Server restarted, so would the PHP processes. In PHP Detached Mode, the PHP processes will continue running independently, even when LiteSpeed Web Server restarts.

When you run in PHP ProcessGroup Mode, PHP process groups are still started by the litespeed process. When the first request for a specific PHP process group comes in, if PHP is not running it, it will be started by LiteSpeed. pstree will show that PHP process is child of the litespeed process. That's normal. What's new is that, as of 5.3, once the litespeed process exits, the PHP process won't quit. It will become independent.

PHP Detached Mode provides an advantage, especially when hundreds of accounts are hosted on the same shared hosting server, with new accounts being rapidly added to it. In cases like this, there is no need to restart all PHP processes during the web server restart. Also, when a user is heavily relying on opcode to reduce the server load, PHP Detached Mode avoids an opcode cache reset during the server restart.

If you are using a control panel, LSWS 5.3 will enable PHP detached mode automatically.

If you are using LSWS 5.3 Native Mode, and explicitly configured an external application for each virtual host, you will need to set Run on Startup to PHP Detached Mode.

In the past, if there were any php.ini changes, you would probably want to restart LSWS to apply the changes(since LSWS will restart PHP processes).

As of LSWS 5.3, PHP runs in detached mode and won't be restarted during LSWS restart. If you want to make php.ini changes effective immediately, there are a few ways to restart PHP processes.

For a User

To restart detached PHP processes for the account (vhost) level, you can touch a .lsphp_restart.txt file under the user's home directory:

touch <user_home_dir>/.lsphp_restart.txt

The user can also restart detached PHP processes from the 'Advanced' page of the LiteSpeed Web Cache Manager cPanel plugin, accessible from within their cPanel dashboard.

For the Server

To restart detached PHP processes for the server level, you can touch a .lsphp_restart.txt file under the <lsws_server_root>/admin/tmp/ directory. Usually, that is /usr/local/lsws/admin/tmp/.

touch /usr/local/lsws/admin/tmp/.lsphp_restart.txt

This can also be accomplished from the 'Actions' page of the LiteSpeed WebAdmin Console or by using the 'Restart Detached PHP Processes' button in the LiteSpeed cPanel/WHM plugin.

All running detached PHP processes will be restarted, but not immediately. Instead, they will restart as soon as the server needs to use that PHP handler.

Stop All Immediately

To stop all lsphp processes immediately, you can manually kill them from the command line:

killall lsphp

PHP Detached Mode doesn't mean that PHP will run forever. It will still follow the Max Idle Time setting. If you want to make PHP live longer, just increase Max Idle Time.

In previous version lower than LSWS 5.2.x, there is a “External App” section to setup PHP external apps and a “Script Hander” section to setup PHP handlers.

On LSWS 5.3, PHP external app and PHP script handler configurations are not required anymore and they will be autoconfigured by the web server. If you run upgrade from 5.2.x or previous version, external apps settings will be carried over. Actually you can delete all PHP external apps and PHP handlers and LSWS will still be working fine. If you install a new fresh LSWS 5.3 installation, most likely you won't see any PHP external apps and PHP handlers defined there anymore. If you see such, don't worry and it is normal for LSWS 5.3. If you still want to define external apps manually, it is ok, and LSWS will honor the settings which actually override the LSWS 5.3 built-in external apps definition.

How to configure PHP setting then if there are no external apps defined there anymore? While a new “PHP” tab has been created in LSWS Web Admin Console and you can set configuration there to detached PHP.

On a WHM/cPanel and CloudLinux environment, ea-phpxx is the default handler pointing to the Easy Apache PHP binary, and alt-phpxx is the default handler pointing to the CloudLinux PHP selector binary. If you have any need to override the default handler binary, for example, to direct ea-php72 to /opt/alt/php72/usr/bin/lsphp, you can create or modify an internal app.

Create or modify existing lsphp to ea-php72:

Change the PHP binary path:

  • Admin
  • Last modified: 2018/09/14 16:09
  • by Michael Alegre