Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:php:process-mode [2018/09/21 15:12]
Michael Alegre [Setup]
litespeed_wiki:php:process-mode [2018/09/24 18:08] (current)
Michael Alegre [Benefits]
Line 14: Line 14:
   * Like [[#​daemon_mode|Daemon mode]], ProcessGroup mode makes use of opcode caching with the added benefit of having per-user opcode caches when running PHP using a suEXEC execution method. Because [[#​daemon_mode|Daemon mode]] forks all processes off a single parent process, every user on that server will share a single large opcode cache. If there are many users, this opcode cache can fill quickly, pushing other user’s scripts out of the cache. By providing per-user opcode caches, each user's scripts remain in their opcode cache irrespective of what other users are doing.   * Like [[#​daemon_mode|Daemon mode]], ProcessGroup mode makes use of opcode caching with the added benefit of having per-user opcode caches when running PHP using a suEXEC execution method. Because [[#​daemon_mode|Daemon mode]] forks all processes off a single parent process, every user on that server will share a single large opcode cache. If there are many users, this opcode cache can fill quickly, pushing other user’s scripts out of the cache. By providing per-user opcode caches, each user's scripts remain in their opcode cache irrespective of what other users are doing.
   * You can enable ProcessGroup mode at either the server or virtual host level through an httpd.conf file directive. By placing this directive in a virtual host level configuration file, you can decide which users get a personal opcode cache.   * You can enable ProcessGroup mode at either the server or virtual host level through an httpd.conf file directive. By placing this directive in a virtual host level configuration file, you can decide which users get a personal opcode cache.
-  * Compared to PHP-FPM + suEXEC where each user must have a process pool manually set up for them, ProcessGroup mode can more easily and quickly achieve the same level of security ​by adding ​the ProcessGroup directive in the server level httpd.conf file while using a suEXEC execution method.+  * Compared to PHP-FPM + suEXEC where each user must have a process pool manually set up for them, ProcessGroup mode can more easily and quickly achieve the same level of security. Simply add the ProcessGroup directive in the server level httpd.conf file while using a suEXEC execution method.
  
 ==== Limitations ==== ==== Limitations ====
-  * ProcessGroup mode keeps one parent process running in addition to all their child processes. This creates a lot of extra processes that you wouldn’t have in LiteSpeed’s [[#​worker_mode|Worker]] or [[#​daemon_mode|Daemon]] modes. You can control this to some degree with the **Max Idle Time** setting ​which informs LiteSpeed Web Server to kill ProcessGroup parent processes that have been idle for longer than the time set.+  * ProcessGroup mode keeps one parent process running in addition to all of it'​s ​child processes. This creates a lot of extra processes that you wouldn’t have in LiteSpeed’s [[#​worker_mode|Worker]] or [[#​daemon_mode|Daemon]] modes. You can control this to some degree with the **Max Idle Time** setting. This setting ​informs LiteSpeed Web Server to kill ProcessGroup parent processes that are idle for longer than the time set.
   * Personal opcode caches must be reasonably large to be of any real use which almost certainly means setting aside more RAM for opcode caching than you would in [[#​daemon_mode|Daemon mode]]. This limits ProcessGroup mode to hosts who are willing to use extra memory to see performance enhancements. Be careful not to portion out too much memory for per-user opcode caches as you could run out of memory.   * Personal opcode caches must be reasonably large to be of any real use which almost certainly means setting aside more RAM for opcode caching than you would in [[#​daemon_mode|Daemon mode]]. This limits ProcessGroup mode to hosts who are willing to use extra memory to see performance enhancements. Be careful not to portion out too much memory for per-user opcode caches as you could run out of memory.
  
Line 23: Line 23:
 To use ProcessGroup mode, **Start By Server** must be set to ''​Yes'',​ ''​Yes (Through CGI Daemon)'',​ or ''​Yes (Through CGI Daemon Async)''​ under **WebAdmin Console > Configuration > External App > your_external_application**. To use ProcessGroup mode, **Start By Server** must be set to ''​Yes'',​ ''​Yes (Through CGI Daemon)'',​ or ''​Yes (Through CGI Daemon Async)''​ under **WebAdmin Console > Configuration > External App > your_external_application**.
  
-You can enable ProcessGroup mode in a control panel environment by placing the ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsphp_processgroup|LSPHP_ProcessGroup]] on''​ directive in an httpd.conf file. If done in a Server level conf file, all Virtual Hosts will use ProcessGroup mode. If done in a Virtual Host level conf file, only that Virtual Host will use ProcessGroup mode. While in a LiteSpeed Web Server (native) environment,​ ProcessGroup mode can be enabled by setting **Instances** to ''​1''​ and setting ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsapi_children_or_php_lsapi_children|LSAPI_CHILDREN]]''​ to a number greater than ''​1''​.+In a LiteSpeed Web Server (native) environment,​ you can enable ProcessGroup mode by setting **Instances** to ''​1''​ and ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsapi_children_or_php_lsapi_children|LSAPI_CHILDREN]]''​ to a number greater than ''​1''​. 
 + 
 +In a control panel environment, you can enable ProcessGroup mode by placing the ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsphp_processgroup|LSPHP_ProcessGroup]] on''​ directive in an httpd.conf file. If done in a Server level conf file, all Virtual Hosts will use ProcessGroup mode. If done in a Virtual Host level conf file, only that Virtual Host will use ProcessGroup mode.
  
 Example configuration for control panel environment:​ Example configuration for control panel environment:​
Line 33: Line 35:
 </​code>​ </​code>​
  
-Note that the two directives ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsphp_processgroup|LSPHP_ProcessGroup]]''​ and ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsphp_workers|LSPHP_Workers]]'' ​are LiteSpeed-specific directives. Apache will not understand ​them and may crash if they are not surrounded ​by an ''<​IfModule LiteSpeed>''​ block.+Note the two LiteSpeed-specific ​directives ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsphp_processgroup|LSPHP_ProcessGroup]]''​ and ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsphp_workers|LSPHP_Workers]]''​. Apache will not understand ​these directives ​and may crash if it encounters them outside of by an ''<​IfModule LiteSpeed>''​ block.
  
 ==== Configuration tips ==== ==== Configuration tips ====
  
   * Setting **Start By Server** to ''​Yes (Through CGI Daemon)''​ or ''​Yes (Through CGI Daemon Async)''​ may save resources by not starting parent processes for idle process groups at startup.   * Setting **Start By Server** to ''​Yes (Through CGI Daemon)''​ or ''​Yes (Through CGI Daemon Async)''​ may save resources by not starting parent processes for idle process groups at startup.
-  * The **Max Idle Time** setting under **WebAdmin console > Configuration > External App > your_external_application** will control how long a parent processes can remain idle before being killed. ​It is not recommended to set **Max Idle Time** ​to ''​-1'' ​when in ProcessGroup mode as it will be converted to a default value of ''​30''​ seconds. +  * The **Max Idle Time** setting under **WebAdmin console > Configuration > External App > your_external_application** will control how long a parent processes can remain idle before being killed. ​When in ProcessGroup mode, LiteSpeed Web Server will treat a **Max Idle Time** ​setting of ''​-1''​ as a default value of ''​30''​ seconds. 
-  * It is recommended to set **Run On Start Up** to ''​No''​ under **WebAdmin console > Configuration > External App > your_external_application**. When set to ''​No'',​ LSWS will start a parent process for each process group only when a user receives traffic. Setting **Run On Start Up** to ''​Yes''​ may result in errors.+  * Set **Run On Start Up** to ''​No''​ under **WebAdmin console > Configuration > External App > your_external_application** to start a parent process for each process group only when a user receives traffic. Setting **Run On Start Up** to ''​Yes''​ may result in errors.
   * If you wish to use [[#​daemon_mode|Daemon mode]] for some users while using ProcessGroup mode for others, change **Run On Start Up** to ''​Yes (Daemon mode)''​ under **WebAdmin console > Configuration > External App > your_external_application**. ProcessGroup mode can then override [[#​daemon_mode|Daemon mode]] by being selectively enabled on virtual hosts that require more powerful opcode caching.   * If you wish to use [[#​daemon_mode|Daemon mode]] for some users while using ProcessGroup mode for others, change **Run On Start Up** to ''​Yes (Daemon mode)''​ under **WebAdmin console > Configuration > External App > your_external_application**. ProcessGroup mode can then override [[#​daemon_mode|Daemon mode]] by being selectively enabled on virtual hosts that require more powerful opcode caching.
   * When **Run on Start Up** is set to ''​Yes''​ or ''​Yes (Daemon mode)'',​ the default value of **Max Idle Time** will be ''​10''​ seconds. You can set this to a very large number like ''​3600''​ to prevent PHP from being stopped by the server too quickly.   * When **Run on Start Up** is set to ''​Yes''​ or ''​Yes (Daemon mode)'',​ the default value of **Max Idle Time** will be ''​10''​ seconds. You can set this to a very large number like ''​3600''​ to prevent PHP from being stopped by the server too quickly.
Line 45: Line 47:
 ==== Additional configurations ==== ==== Additional configurations ====
  
-  * The maximum number of child processes that a parent process can spawn can be controlled ​with the ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsphp_workers|LSPHP_Workers]]''​ directive. If set, the **PHP suEXEC Max Conn** setting under **WebAdmin console > Configuration > Server > General > Using Apache Configuration File** ​will be overridden.+  * You can control the maximum number of child processes that a parent process can spawn with the ''​[[litespeed_wiki:​php:​lsapi-environment-variables#​lsphp_workers|LSPHP_Workers]]''​ directive. If set, this will override ​the **PHP suEXEC Max Conn** setting under **WebAdmin console > Configuration > Server > General > Using Apache Configuration File**.
   * You can set opcode cache size per-user in their php.ini file. The steps to set this depends on which opcode cache you’re using.   * You can set opcode cache size per-user in their php.ini file. The steps to set this depends on which opcode cache you’re using.
  
Line 51: Line 53:
 ==== Special notes for use with cPanel ==== ==== Special notes for use with cPanel ====
  
-  * The ''​ProcessGroup''​ directive ​should be placed ​in an include file to avoid being overwritten during WHM upgrades. When configuring ''​ProcessGroup''​ at the Server level, the directive ​should be placed ​in ''/​usr/​local/​apache/​conf/​includes/​pre_virtualhost_global.conf''​. When configuring ''​ProcessGroup''​ at the Virtual Host level, the directive ​should be placed ​in a [[https://​confluence2.cpanel.net/​display/​EA/​Modify+Virtualhost+Containers+With+Include+Files|Virtual Host level include file]].+  * Place the ''​ProcessGroup''​ directive in an include file to avoid it being overwritten during WHM upgrades. When configuring ''​ProcessGroup''​ at the Server level, ​place the directive in ''/​usr/​local/​apache/​conf/​includes/​pre_virtualhost_global.conf''​. When configuring ''​ProcessGroup''​ at the Virtual Host level, ​place the directive in a [[https://​confluence2.cpanel.net/​display/​EA/​Modify+Virtualhost+Containers+With+Include+Files|Virtual Host level include file]].
   * LiteSpeed Web Server versions 5.2.8 and below will stop all PHP processes when performing a restart. This has the negative effect of resetting the opcode cache. Starting from LSWS 5.3, LSPHP will run in detached mode by default allowing PHP processes to survive LSWS restarts. The LSPHP parent will follow the **[[https://​www.litespeedtech.com/​docs/​webserver/​config/​extapps/​lsapi#​extMaxIdleTime|Max Idle Time]]** setting in this case.   * LiteSpeed Web Server versions 5.2.8 and below will stop all PHP processes when performing a restart. This has the negative effect of resetting the opcode cache. Starting from LSWS 5.3, LSPHP will run in detached mode by default allowing PHP processes to survive LSWS restarts. The LSPHP parent will follow the **[[https://​www.litespeedtech.com/​docs/​webserver/​config/​extapps/​lsapi#​extMaxIdleTime|Max Idle Time]]** setting in this case.
  
Line 60: Line 62:
 ==== Benefits ==== ==== Benefits ====
   * Daemon mode enjoys reduced overhead and faster process generation by forking child processes instead of creating new processes for each new request from the same user.   * Daemon mode enjoys reduced overhead and faster process generation by forking child processes instead of creating new processes for each new request from the same user.
-  * When running PHP using a suEXEC execution method, Daemon mode will conserve resources by killing parent processes that have been idle too long. This is more efficient than Apache + PHP-FPM where at least one process is always running in each user's pool. In addition to this, many suEXEC implementations start PHP processes as standalone processes ​where each standalone process has its own opcode cache. This leaves only a tiny window to take advantage of that process'​s opcode cache before the process ends. When running in Daemon mode, all PHP processes share the same opcode cache memory. This allows for a larger opcode cache memory block with a far improved cache hit rate due to less frequent flushes.+  * When running PHP using a suEXEC execution method, Daemon mode will conserve resources by killing parent processes that have been idle too long. This is more efficient than Apache + PHP-FPM where at least one process is always running in each user's pool. In addition to this, many suEXEC implementations start PHP processes as standalone processeseach with their own opcode cache. This leaves only a tiny window to take advantage of that process'​s opcode cache before the process ends. When running in Daemon mode, all PHP processes share the same opcode cache memory. This allows for a larger opcode cache memory block with an improved cache hit rate due to less frequent flushes.
  
 ==== Limitations ==== ==== Limitations ====
-  * Daemon mode does not allow the use of custom per-user php.ini files. As a result, LiteSpeed Web Server will automatically switch to [[#​worker_mode|Worker mode]] at the Server level if a custom php.ini file is detected.+  * Daemon mode does not allow the use of custom per-user php.ini files. As a result, LiteSpeed Web Server will automatically switch to [[#​worker_mode|Worker mode]] at the Server level if it detects ​a custom php.ini file.
   * Due to it's incompatibility with custom php.ini files, Daemon mode is not compatible with CloudLinux'​s PHP Selector.   * Due to it's incompatibility with custom php.ini files, Daemon mode is not compatible with CloudLinux'​s PHP Selector.
  
Line 75: Line 77:
 ==== Benefits ==== ==== Benefits ====
   * Worker mode is compatible with custom php.ini files including CloudLinux’s CageFS php.ini files, allowing the use of CloudLinux'​s PHP Selector. ​   * Worker mode is compatible with custom php.ini files including CloudLinux’s CageFS php.ini files, allowing the use of CloudLinux'​s PHP Selector. ​
-  * When running PHP using a suEXEC execution method, ​Worker mode will conserve resources by killing processes that have been idle too long. This is more efficient than Apache + PHP-FPM where at least one process is always running in each user's pool.  ​+  * Worker mode conserves resources by killing idle processes. ​When running PHP using a suEXEC execution method, ​this is more efficient than Apache + PHP-FPM where at least one process is always running in each user's pool.  ​
  
 ==== Limitations ==== ==== Limitations ====
-  * Worker mode will create ​a new PHP process when needed. This results ​in the process'​s opcode cache flushing ​each time the processes exits, making ​Worker mode incompatible with opcode and APCu caching. For this reason, ​it is recommended to only use Worker mode if custom.php files are needed but server resources are too limited for [[#​processgroup_mode|ProcessGroup mode]].+  * Worker mode creates ​a new PHP process when needed, resulting ​in the process'​s opcode cache flushing ​when the processes exits. This makes Worker mode incompatible with opcode and APCu caching. For this reason, ​you should ​only use Worker mode if you need custom php.ini files and server resources are too limited for [[#​processgroup_mode|ProcessGroup mode]].
   * Creating a new processes has more overhead than forking child processes. This may cause Worker mode to be slightly slower than [[#​daemon_mode|Daemon]] or [[#​processgroup_mode|ProcessGroup]] modes. This overhead can be greatly reduced by running in [[#​daemon_mode|Daemon mode]] by setting **Start By Server** to ''​Yes (Through CGI Daemon)''​ or ''​Yes (Through CGI Daemon Async)''​ under **Configuration > External App > your_external_application**.   * Creating a new processes has more overhead than forking child processes. This may cause Worker mode to be slightly slower than [[#​daemon_mode|Daemon]] or [[#​processgroup_mode|ProcessGroup]] modes. This overhead can be greatly reduced by running in [[#​daemon_mode|Daemon mode]] by setting **Start By Server** to ''​Yes (Through CGI Daemon)''​ or ''​Yes (Through CGI Daemon Async)''​ under **Configuration > External App > your_external_application**.
  
 ==== Setup ==== ==== Setup ====
-Worker mode will be used when none the setting requirements for [[#​processgroup_mode|ProcessGroup mode]] (default) or [[#​daemon_mode|Daemon mode]] have been met. LiteSpeed Web Server may also automatically switch to Worker mode at the Server level if a custom php.ini file is detected when running in [[#​daemon_mode|Daemon mode]].+LiteSpeed Web Server will use Worker mode when none of the setting requirements for [[#​processgroup_mode|ProcessGroup mode]] (default) or [[#​daemon_mode|Daemon mode]] have been met. LiteSpeed Web Server may also automatically switch to Worker mode at the Server level if it detects ​a custom php.ini file while running in [[#​daemon_mode|Daemon mode]].
  
 ===== Mode Comparison ===== ===== Mode Comparison =====
Line 90: Line 92:
 ^ Number of parent processes ​                       |  One for each process group\\ (each user)  |  1  |  0  | ^ Number of parent processes ​                       |  One for each process group\\ (each user)  |  1  |  0  |
 ^ Customize number of processes per account? |  Yes  |  Yes  |  Yes  | ^ Customize number of processes per account? |  Yes  |  Yes  |  Yes  |
-^ Can be enabled ​only for certain virtual hosts? |  Yes  |  No  |  No  |+^ Can enable ​only for certain virtual hosts? |  Yes  |  No  |  No  |
 ^ Custom php.ini supported? (Including CageFS custom php.ini) |  Yes  |  No  |  Yes  | ^ Custom php.ini supported? (Including CageFS custom php.ini) |  Yes  |  No  |  Yes  |
 ^ Opcode caching |  Dedicated per user  |  Shared throughout server ​ |  No  | ^ Opcode caching |  Dedicated per user  |  Shared throughout server ​ |  No  |
  
  • Admin
  • Last modified: 2018/09/21 15:12
  • by Michael Alegre