Home > Backend Development > PHP Problem > Three ways to run php

Three ways to run php

藏色散人
Release: 2023-03-04 11:36:01
Original
5459 people have browsed it

The three running methods of php are: 1. Implemented through the built-in module of HTTPServer; 2. Implemented through CGI; 3. Implemented through FastCGI.

Three ways to run php

Recommended: "PHP Video Tutorial"

Three ways of running PHP

Three operating modes: mod_php5, cgi, fast-cgi

1. Implemented through the built-in module of HTTPServer,

For example, Apache's mod_php5, similar Apache's built-in mod_perl can Support for perl;

2. Implementation through CGI

This is just like the previous CGI of perl. The disadvantage of this method is poor performance, because every time the server encounters These scripts require restarting the script parser to execute the script and return the results to the server. On the other hand, it is not very safe.

This method is almost rarely used.

3. The latest one is called FastCGI.

The so-called FastCGI is an improvement on CGI. It generally adopts a C/S structure. Generally, the script processor will start one or more daemon processes. Every time HTTPServer encounters a script, it is directly delivered to the FastCGI process for execution, and then the result (usually HTML) is returned. to the browser.

A small problem with this method is that when encountering frequent requests with large traffic, the daemon process of the script processor may be overloaded and become very slow, or even cause a memory leak;

But the advantage compared to Apache's built-in module method is that the server and script parser are completely separated and responsible for their own responsibilities, so the server is no longer bloated and can concentrate on responding to static files or returning the results of the dynamic script parser. Give the user client.

So compared to Apache's built-in module method, sometimes the performance is much improved.

Some people have tested that it may be 5 to 10 times faster than Apache mod_php.

3.1. FastCGI common modes:

lightppd spawn-fcgi

nginx PHP-FPM

a, both of the above FastCGI is used to support PHP, so HTTPServer is completely liberated and can respond better and handle concurrently.

b. Since spawn-fcgi is part of lighttpd, if lighttpd is installed, spawn-fcgi will generally be used to support PHP. However, some users currently say that lighttpd’s spwan-fcgi will fail during high concurrent access. The memory leak mentioned above may even automatically restart fastcgi.

Unlike lighttpd, nginx comes with fastcgi (spawn-fcgi), so it is completely lightweight. It must use a third-party FastCGI processor to parse PHP, so it actually looks like this nginx is very flexible and can be connected to any third-party parsing processor to parse PHP.

nginx can use spwan-fcgi (lighttpd needs to be installed together, but the port needs to be avoided for nginx. Some older blogs have tutorials on this installation), but since spawn-fcgi has the users mentioned above The defects gradually discovered, now the use of nginx spawn-fcgi combination is gradually reduced.

c. Due to the defects of spawn-fcgi, a new third-party (currently still, I heard that they are working hard to add it to PHP core in the near future) FastCGI processor for PHP has appeared, called PHP-FPM. Compared with spawn-fcgi, it has the following advantages:

Since PHP-FPM is developed as a PHP patch, it needs to be compiled together with the PHP source code during installation, which means that it is compiled into PHP core. Therefore, it is better in terms of performance;

At the same time, it is also better than spawn-fcgi in handling high concurrency, at least it will not automatically restart the fastcgi processor.

Therefore, as mentioned above, due to the lightweight and flexibility of nginx, its current performance is superior, and more and more people are gradually using this combination: nginx PHP/PHP-FPM.

The above is the detailed content of Three ways to run php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template