Today we will talk a bit about the different modes in which the PHP Engine can run under the Apache web server and what the differences are. The two modes available are mod_php and CGI.
- PHP running under mod_php means the PHP engine is activated and configured only one time exactly when you start apache. The biggest advantage of this mode is that PHP runs very fast since it can take advantage of caching and does not have to perform certain tasks every time a PHP script is being executed. One of those tasks is for example loading the configuration. This is also one of the big dis-advantages mod_php has. To make any configuration change, PHP or actually Apache needs to be restarted. Another negative for mod_php is the fact that is executed under the user under which Apache runs. This creates various permission issues especially for files created by the PHP script.
- PHP running in CGI mode means the PHP Engine is called whenever Apache detects a php script needs to be parsed. It has th advantage that configuration changes can take effect immediately but it also makes the script execution a lot slower since the Engine has to read its configuration on each and every php files that needs to be executed. In addition, it is much harder to take advantage of memory caching since every call to a PHP script creates a whole new environment. So basically a script you are executing multiple times will need to be loaded into memory from the harddisk every time. The biggest advantage of running PHP in CGI mode is the fact that it is executed under the FTP user account it belongs to. It creates a lot less issues with writing files via PHP Script.
With HelpingHost.com you can switch the mode in which PHP runs on each of your websites independently. Simply login to your hosting control panel and edit the Web Service settings of the domain you are working on. Just remember, it can take up to 20 minutes after you hit “Apply Changes” until the web server picks up your changes.
You know have the option to choose the FastCGI mode to run PHP.
This mode combines advantages of both, mod_php and CGI mode.
Basically it starts PHP one time on the first request of a PHP script and keeps running for the next several requests. This will dramatically speed up the speed of your PHP scripts.
As stated before, you can just switch your website from within the hosting control panel to use PHP 5.3, 5.4 and 5.5 in FastCGI mode.
We now have PHP 5.6, 7.0, 7.1 and PHP 7.2 available.
In addition a new PHP mode where PHP runs under mod_lsapi is now available.
This new mod_lsapi is based on the LightSpeed API. It is ultra fast. Test it out!