What are the two common running modes of PHP?
There are two common ways of running PHP.
1. In CGI mode, the web server starts a separate PHP interpreter process to execute PHP scripts every time it processes a request. This mode involves communication between the PHP interpreter and the web server through standard input and output. However, CGI mode is relatively slower because it requires starting and closing a new PHP interpreter process for each request.
Module Pattern: In the module pattern, PHP is embedded directly into the web server in the form of a built-in module (such as the Apache module mod_php). The PHP interpreter is loaded into the server’s memory when the server starts and remains active to handle all requests for PHP scripts. With this pattern, there is no need to start a new PHP interpreter process for each request, making it more efficient than CGI mode.
Different running modes can be chosen based on different needs. Typically, using the CGI mode is more convenient during the development and debugging stages because it allows for easier restarting of the PHP interpreter and error log viewing. On the other hand, in a production environment, the module mode is more commonly used as it offers better performance and response speed.