This is an old revision of the document!
PHP Detached Mode in LiteSpeed Web Server
What's PHP detached mode?
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 Process Group 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.
Benefit of PHP detached mode?
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.
How to restart detached PHP processes?
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 will be running as detached mode and won't be restarted during LSWS restart. If you want to make You can make php.ini
changes effective immediately, there are a few ways to start php processes.
Restart detached PHP processes for a user
To restart detached PHP processes for account (vhost) level, you can touch a “.lsphp_restart.txt” file under user's home directory:
touch <user_home_dir>/.lsphp_restart.txt
Restart detached PHP processes for the server
To restart detached PHP processes for server level, you can touch a “.lsphp_restart.txt” file under “<lsws_server_root>/admin/tmp/“ directory:, usually, is ”/usr/local/lsws/admin/tmp/“ directory
touch /usr/local/lsws/admin/tmp/.lspohp_restart.txt
Running detached PHP processes will be restarted, not immediately, instead, as soon as server need use that PHP handler.
Stop all lsphp processes immediately
To stop all lsphp processes immediately, you can manually kill all PHP processes from command line:
killall lsphp
Will PHP processes running forever in detached mode
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.
PHP Auto Configuration for different Control Panels
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.
How to override default PHP handler binary path?
On a WHM/cPanel and CloudLinux environment, ea-phpxx is default handler pointing to easy apache php binary and alt-phpxx is default handler pointing to CloudLinux PHP selector binary. If you have any need to override the default handler binary, for example, you would like to direct ea-php72 to /opt/alt/php72/usr/bin/lsphp, you can create/modify internal app for such override.