How does the HTTP server support PHP? _ PHP Tutorial

Source: Internet
Author: User
How does the HTTP server support PHP ?. Currently, there are three types of server HTTPServer support for PHP: the built-in modules of HTTPServer, for example, mod_php5 of Apache, similar to the built-in mod_perl of Apache, the following three types of HTTP Server support for PHP are available for each Server:

  • Implemented through the built-in modules of HTTP Server, such as Apache mod_php5. similar to Apache's built-in mod_perl, perl can be supported;
  • Through CGI, this is like the previous perl CGI. the disadvantage of this method is poor performance, because every time the server encounters these scripts, it needs to restart the script parser to execute the script and return the result to the server. on the other hand, it is not secure and is rarely used in this aspect.
  • The latest one is FastCGI. FastCGI is an improvement on CGI. It generally uses a C/S structure. Generally, the script processor starts one or more daemon processes. each time the HTTP Server encounters a script, it is directly delivered to the FastCGI process for execution, then return the result (usually html) to the browser.

A small problem with the FastCGI method is that when large traffic is frequently requested, the daemon process of the script processor may be overloaded and become slow, or even cause memory leakage. However, the advantage of comparing the built-in modules of Apache is that the Server and the script parser are completely independent of each other, so the Server is no longer bloated, you can concentrate on static file response or return the results of the dynamic script parser to the user client. Therefore, compared with the built-in modules of Apache, the performance sometimes needs to be improved a lot. Some tests may reach 5 ~ of Apache + mod_php ~ 10 times.

FastCGI is commonly used in two types of stack:

  • Ligthttpd + spawn-fcgi
  • Nginx + PHP-FPM (also available with spawn-fcgi)

As mentioned above, both of these structures use FastCGI to support PHP. Therefore, the HTTP Server is completely liberated and can better respond to and concurrently process requests. Therefore, both lighttpd and nginx have the reputation of small, but powerful and efficient.

The two can also be considered as good or bad. since spawn-fcgi is part of lighttpd, lighttpd is installed and generally supports php using spawn-fcgi, however, some users say that when the spwan-fcgi of ligttpd is accessed in high concurrency, the memory leakage mentioned above may even automatically restart fastcgi. That is, if the PHP script processor is on the machine and the user accesses it at this time, there may be white pages (that is, PHP cannot be parsed or error ).

Unlike lighttpd, which includes fastcgi (spawn-fcgi), Nginx is completely lightweight and can only be parsed using a third-party FastCGI processor, as a result, nginx is very flexible. it can be connected to any third-party processor for parsing to achieve PHP parsing (in nginx. conf ).

Nginx can use spwan-fcgi (lighttpd needs to be installed together, but the Port needs to be avoided for nginx. some earlier blogs have Installation Tutorials in this regard ), but since spawn-fcgi has the defects gradually discovered by users described above, it is now slowly reducing the use of nginx + spawn-fcgi combinations.

Due to spawn-fcgi defects, a new third-party PHP FastCGI processor (currently, I heard it is working hard to join PHP core in the near future) has emerged, is called PHP-FPM (can google ). Compared with spawn-fcgi, it has the following advantages:

Because it is developed as a patch for PHP, it needs to be compiled together with the php source code during installation, that is, compiled into the php core, so it should be better in terms of performance. At the same time, it is superior to spawn-fcgi in terms of processing high concurrency, at least it will not automatically restart the fastcgi processor. Google can understand the specific algorithms and designs used.

Therefore, as mentioned above, nginx is simple and flexible, so the current performance is superior, more and more people gradually use this combination: nginx + PHP/PHP-FPM.

Summary

Currently, three types of stacks are quite popular in HTTPServer:

  • Apache + mod_php5
  • Lighttp + spawn-fcgi
  • Nginx + PHP-FPM

Server supports PHP in three ways: through the built-in HTTP Server module, for example, Apache mod_php5, similar to Apache built-in mod_perl...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.