Auto-Configurations for PHP Application Servers on AccuWeb.Cloud
AccuWeb.Cloud’s dynamic resource organization complements the fundamental PHP structure to optimize PHP integration within the Platform as a Service (PaaS) environment. When adjusting the allocated resources, such as cloudlets count, the platform seamlessly adapts the PHP directives to suit the new conditions automatically. Nevertheless, users retain the option to manually configure parameters within their server’s configuration file.
It’s important to note that the handling and dispatching system for basic requests varies across different PHP application servers, resulting in the utilization of different directives. However, despite these variations, the functionality of these parameters often remains similar. To explore the detailed directives relevant to a particular application server, please refer to the corresponding section outlined below.
Additionally, you have the option to learn about How the auto-configuration works.
Alternatively, if you prefer to manually redefine the values, you can proceed to the section titled How to Disable the Automatic Optimization in this guide.
Apache PHP Auto Adjustable Settings
Dynamic request handling in Apache PHP is facilitated through the utilization of the prefork Multi-Processing Module (MPM). This module optimizes server performance by fully utilizing its potential. The directives related to MPM can be found in the main Apache configuration file located at /etc/httpd/conf/httpd.conf.
Below is a comprehensive list of parameters that the platform configures for the prefork module:
- StartServers: This parameter sets the number of child server processes created during startup.
- MinSpareServers (MaxSpareServers): These parameters define the minimum (maximum) number of server processes to be kept in reserve to handle incoming requests efficiently.
- ServerLimit: This parameter sets the maximum allowed value for the MaxRequestWorkers directive, effectively limiting the number of simultaneous requests that can be processed by the server.
- MaxRequestWorkers: Configuring this parameter determines the maximum number of simultaneous requests that the server can handle efficiently.
- MaxConnectionsPerChild: This parameter defines the maximum number of requests that a single child process can serve before it is terminated and replaced with a new one.
Based on the allocated resources, such as the number of dynamic cloudlets reserved for the Apache PHP server, and the capacity of the CPU provided by your hosting provider, AccuWeb.Cloud automatically adjusts the ServerLimit and MaxRequestWorkers parameters.
MaxRequestWorkers = ServerLimit = min( {containerRam} / 30MiB, {coresCount} * 5 )
As per this statement, both directives are set equal to the lower value between:
- The amount of RAM allocated to the node, divided by 30.
- The number of cores on the hosting provider’s physical server where the container is located, multiplied by 5.
In this manner, the parameters are dynamically adjusted based on the number of allocated cloudlets, ensuring they do not exceed the hardware limits.
- Setting ServerLimit too high may result in the allocation of unused shared memory, while setting it too low may limit the server’s performance potential.
- Ensure that MaxRequestWorkers is set to accommodate the expected number of simultaneous requests while also being mindful of available RAM to prevent memory issues.
You might also want to check out how the auto-configuration operates or learn how to disable automatic optimization if you’re inclined to set custom values for these directives.
NGINX PHP Auto Adjustable Settings
Request handling in the NGINX PHP application server is managed by the FastCGI Process Manager (FPM), which can be configured via the /etc/php-fpm.conf file. This file is automatically added to the favorites list in the container file manager for easy access.
By default, FPM operates in the ondemand mode, as specified by the “pm” directive. In this mode, FPM spawns new processes as needed (i.e., on demand) and removes idle ones. The key parameters for this mode are:
- pm.max_children: This parameter defines the maximum number of child processes. It is typically set equal to the number of CPU cores available for the container, with a minimum value of 2.
- pm.process_idle_timeout: This parameter sets the delay before killing an idle process, with a default value of 60 seconds.
If you wish to define this directive explicitly without disabling the automatic optimization, you can utilize the appropriate PHPFPM_MAX_CHILDREN variable.
If necessary, you have the option to disable the automatic optimization to change the FPM mode and adjust other directives. However, it’s crucial to exercise caution as incorrect values can lead to instability in your NGINX PHP server.
For enhanced performance, the PHP-FPM listener uses a UNIX domain socket instead of the standard TCP socket. This approach is better suited for communication within the same host, as it bypasses certain checks and operations like routing, ultimately improving efficiency.
How the PHP Auto-Configuration Works
You can observe how the parameters mentioned above are adjusted based on the allocated resources. Let’s take the example of the Apache PHP server:
1. Begin by creating a new PHP environment with the Apache PHP application server inside, if you haven’t already done so.
Next, navigate to the Config button for this node and locate the prefork module configurations in the /etc/httpd/conf/httpd.conf file.
Take note of the directive values corresponding to the current number of cloudlets.
2. Proceed to adjust the resource limit for the Apache PHP server using the “Change Environment Topology” button. Afterward, refresh the /etc/httpd/conf/httpd.conf file and compare the prefork parameter values with the ones previously recorded.
Indeed, the directive values increased automatically as a result of a higher amount of available resources being allocated, demonstrating that the automatic optimization is functioning. Similarly, if the cloudlets count were to be decreased, the values of these parameters would be reduced accordingly.
Disable Automatic Optimization
If you wish to specify your own custom values rather than relying on the automatically configured directives, it’s necessary to disable the automatic optimization. Otherwise, any custom changes you make will be reverted during container restart or updates.
To manually modify any of the auto-configured settings, you can set the JELASTIC_AUTOCONFIG environment variable to false.
Legacy Implementation
For legacy implementations on old containers, you simply need to remove the line containing the optimization mark at the beginning of the relevant configuration file:
For Apache PHP, locate and delete the line “# Jelastic autoconfiguration mark” within the /etc/httpd/conf/httpd.conf file.
For NGINX PHP, find and remove the line “; Jelastic autoconfiguration mark” within the /etc/php-fpm.conf file.
Once you’ve removed the corresponding string, the parameters’ values will no longer be automatically configured by the platform’s optimization mechanism, allowing you to specify your custom parameters. Be sure to save the file to apply the new configurations.