PHP is a widely used server-side scripting language used for web development and dynamic page generation. It can run as a CGI (Common Gateway Interface) application or as a module such as the Apache HTTP server.
CGI (Common Gateway Interface) is a universal standard for connecting web servers and web applications. It allows the web server to send requests to web applications and receive responses. Among them, PHP CGI refers to the way to connect the PHP interpreter and the Web server using the CGI standard protocol.
PHP has two main CGI solutions: PHP-CGI and PHP-FPM. The following introduces their differences.
PHP-CGI is the standard CGI solution for PHP. It uses a process pool to run the PHP interpreter, with each request creating a new process. It uses a separate process to handle each request, which can cause some performance issues. Because it requires reloading the PHP interpreter and related library files for each request. This process requires more time and resources.
PHP-FPM is another CGI solution for PHP that improves PHP's performance issues. It uses a pool of processes to run the PHP interpreter, and each process can handle multiple requests. In PHP-FPM, the interpreter thread is awakened when a request arrives and remains active after the request processing is completed. This reduces the processing time of each request because the interpreter and library files do not need to be reloaded when processing a request, but already existing threads are reused.
PHP-FPM also provides better ability to schedule and control the concentrator. It allows you to set the number of threads that can be used, and how newly arriving requests are handled when the thread pool is full. This better keeps the server responsive under dynamic loads.
PHP-FPM is the recommended solution for PHP because it can provide better performance and scalability. PHP-FPM has better thread pool management than PHP-CGI, has better performance and better dynamic load management capabilities. PHP-FPM also supports FastCGI protocol and can communicate with various web servers (such as Nginx, Apache, etc.).
Although PHP-CGI is PHP's standard CGI solution, considering performance, you can choose to use PHP-FPM. For small websites or development environments, PHP-CGI can be used, but in a production environment, in order to ensure good performance and scalability, it is recommended to use PHP-FPM.
In short, PHP can connect to the web server through the CGI protocol, using PHP-CGI or PHP-FPM as a CGI solution. PHP-FPM is a proposed solution for PHP that provides better performance and scalability. Which CGI solution to use depends on your usage, including server load, traffic, etc.
The above is the detailed content of php cgi difference. For more information, please follow other related articles on the PHP Chinese website!