While learning about PHP and LSAPI settings in OpenLiteSpeed , I was wondering how to set them up. However, it was difficult to find the right settings to prevent server load, so I looked for another way and found out about Dynamic Scaling, a dynamic expansion feature.
Dynamic Scaling here primarily provides the ability to automatically adjust the number of PHP processes. It detects the load on the server and adds or removes child processes as needed.
For example, when the server load is high, it can automatically scale up PHP processes to handle more requests, and when the load is low, it can reduce unnecessary processes to save resources.
However, OpenLiteSpeed does not provide full dynamic scaling capabilities. After looking into the solution, I found that full dynamic scaling requires external tools, but dynamic scaling is possible.
Looking at the documentation, we can see that OpenLiteSpeed is dynamically scalable, but requires additional resource management and server optimization for perfect dynamic scaling.
However, for those of us who lack knowledge about servers like me, the configuration was quite difficult. So, I looked into how to set up applicable dynamic expansion and applied it this time.
If your site is slow or your system resources (CPU, RAM) are overloaded, try upgrading your server or applying dynamic scaling to manage processes more efficiently.
Table of Contents
Add External App settings
You can access the OpenLiteSpeed Webadmin by typing : 7080 after your domain or IP address in your browser . Then go to ‘Server Configuration’, select ‘External App’ from the top menu, and click the edit button shown above.
If you go into LiteSpeed SAPI App editing, there are Max Connections and Environment, and you can apply dynamic expansion by setting them here.
Max Connections : 45
Environment: PHP_LSAPI_CHILDREN=30
LSAPI_AVOID_FORK=1
If you set it as above, let’s find out what it means.
Max Connections Meaning
- Max Connections refers to the maximum number of connections that PHP LSAPI can handle simultaneously.
- This value is closely related to the PHP_LSAPI_CHILDREN value, and is efficient when Max Connections ≥ PHP_LSAPI_CHILDREN.
PHP_LSAPI_CHILDREN=30Meaning
- Enables up to 30 PHP processes to run concurrently.
- This value may need to be adjusted depending on your server’s CPU and memory performance.
- Setting it too high can result in poor performance due to server memory shortage.
LSAPI_AVOID_FORK=1 Meaning
- Save resources by creating PHP processes only when needed and terminating them when no requests are made.
- Since WordPress primarily handles short PHP requests, this setting is beneficial for reducing processing and increasing efficiency.
The above settings are my own, so you will need to adjust them to suit your system environment. Please refer to the explanation below.
How to set it up optimally
Set the appropriate PHP_LSAPI_CHILDREN value based on the number of CPU cores and memory capacity of your server.
- 2 core CPU, 4GB RAM: PHP_LSAPI_CHILDREN=30 recommended
- 4 core CPU, 8GB RAM: PHP_LSAPI_CHILDREN=50 recommended
Considering traffic patterns,
- Low traffic: PHP_LSAPI_CHILDREN=10, Max Connections=15 or so
- Medium traffic: PHP_LSAPI_CHILDREN=30, Max Connections=45 or so
- High traffic: PHP_LSAPI_CHILDREN=50, Max Connections=75~100
Advantages of the setting
- Resource efficiency: Optimizes memory usage by creating only as many PHP processes as needed when the server is busy and reducing processes when the load is light.
- Improved response times: Handles many concurrent requests, reducing response delays even when the number of visitors suddenly increases.
- Load Protection: When too many requests come in, process limits are in place to prevent CPU and memory from becoming overloaded.
Since ‘Server Configuration’ is a global setting, the External App of the Virtual Host can operate independently. Therefore, it is recommended to set dynamic expansion to the same value in both places to avoid unexpected behavior.
Virtual Host is also set up in the same way
After entering Virtual Hosts, select your domain and then go to Edit in External App.
Then, as with the global settings, you can modify the dynamic expansion settings. If you have completed the settings as described above, you can restart the server by clicking the IP address in the upper left corner of OpenLiteSpeed Webadmin.
It was difficult to find appropriate values for the above settings based on various factors such as server environment and traffic. So, I added examples of settings based on CPU, RAM, and traffic. Please refer to these contents and proceed with the settings.
And since server load slows down the site speed, please check periodically using tools such as Cyberpanel, Top, and Htop. If there is a load on the system, please adjust the values based on the explanation above.
▶ How to fix /feed/ duplicate pages in Google Search Console
▶ How to Resolve CORS Errors on the OpenLiteSpeed Web Server
▶ How to apply the HTTP/3 protocol to the OpenLiteSpeed web server