1. PHP operating mode under Apache and ngnix.
1) There are three operating modes under Apache: CGI mode, modular mode, and FastCGI mode.
CGI mode is a relatively primitive way. Every time it receives a request, it will call php.exe, parse php.ini, load DLL, etc., which is naturally slow.
Modular mode, Apache runs php in this way by default. This is to compile php into its own module. There is no need to call the php.exe program when processing php scripts. The entire process is processed only by the Apache process, which is relatively stable.
FastCGI mode is an upgraded version of CGI mode. implements technical features similar to the connection pool, maintains the connection to the background, can be used when the request comes, and is ready to be disconnected when it ends. The next request is connected, unlike the original CGI mode that needs to be called every time .
Blocking type, a process will be created for each request, unlike Nginx which can use the same process to handle multiple requests.
2), CGI is not supported under the Nginx server, and it runs in FastCGI mode by default, and because it is asynchronous and non-blocking, it supports high concurrency scenarios.
2. Advantages of nginx over apache : 1. Lightweight, same as web service, better than apache Occupies less memory and resources 2. Anti-concurrency, nginx processes requests asynchronously and non-blockingly, while apache is blocking (synchronous multi-process) , nginx can maintain low resources under high concurrency Low consumption and high performance 3. Highly modular design, writing modules is relatively simple 4. The community is active and various high-performance modules are produced quickly
Three , The advantages of apache over nginx:
1. rewrite, more powerful than nginx’s rewrite
2. The processing performance of dynamic pages is better than nginx inx is good
3. There are so many modules that you can basically find everything you can think of 4. Few bugs, nginx has relatively many bugs
5、 Super stable
Existence is the reason. Generally speaking, web services that require performance use nginx. If you don’t need performance and just want stability, then use apache .
The various functional modules of the latter are implemented better than the former. For example, the ssl module is better than the former and has more configurable items. One thing to note here is that the epoll (kqueue on freebsd) network IO model is the fundamental reason for nginx's high processing performance, but not all situations are epoll's winner. If it provides static services, only a few file, apache's select model may be more performant than epoll. Of course, this is just an assumption based on the principles of the network IO model. The real application still needs to be tested before talking about it.
4. As a Web server: Compared to Apache, Nginx uses less Resources , support more concurrency Connection reflects higher efficiency, this
This makes Nginx especially popular with web hosting providers. In the case of high connection concurrency, Nginx is a good alternative to the Apache server: Nginx is one of the software platforms often chosen by virtual host business owners in the United States. It can support responses of up to 50,000 concurrent connections, Thank you Nginx chose epoll and kqueue as the development model for us. Nginx as a load balancing server: Nginx can not only directly support Rails and PHP programs internally to provide external services, but also support external services as an HTTP proxy server. Nginx is written in C, and its system resource overhead and CPU usage efficiency are much better than Perlbal. As a mail proxy server: Nginx is also a very excellent mail proxy server (one of the earliest purposes for developing this product First, as a mail proxy server), Last.fm describes a successful and wonderful experience. Nginx is a server that is very simple to install, has a very concise configuration file (it can also support perl syntax), and has very few bugs: Nginx It is particularly easy to start, and it can run almost 24/7, without restarting even if it runs for several months. You can also upgrade the software version without interrupting the service.
5. Nginx configuration is simple, Apache is complex Nginx static processing performance is more than 3 times higher than Apache Apache’s support for PHP is relatively simple, Nginx needs to cooperate with other backends Use Apache has more components than Nginx Now Nginx is the first choice for web servers
Six , the core difference is that apache is a synchronous multi-process model , one connection corresponds to one process; nginx is asynchronous , multiple connections (10,000 levels) can correspond to one process
7. nginx handles static files well and consumes less memory .But there is no doubt that apache is still the mainstream at present, with many rich features. So it still needs to be matched. Of course, if it is determined that nginx suits the needs, then using nginx will be a more economical way. apache has inherent disadvantages The disadvantage of supporting multi-core processing load is that it is useless. It is recommended to use nginx as the front end and apache as the back end. It is recommended that large websites use the cluster function of nginx. For how to configure LNMPA, you can check http://www.freehao123.com/lnmpa/ 8. Judging from personal past usage, the load capacity of nginx is much higher than that of apache. The latest server also uses nginx. Moreover, after changing the configuration of nginx, you can -t test whether the configuration is correct.
There is a problem. When apache is restarted, it is found that the configuration is wrong and it will crash. I will be very careful when making changes. Now there are many cluster sites, front-end nginx anti-concurrency, back-end apache cluster,
The cooperation is also good.
9. nginx is useless for handling dynamic requests. Generally, dynamic requests need to be done by apache, and nginx is only suitable for static and reverse . 10. From my personal experience, nginx is a very good front-end server with very good load performance. It is effortless to open nginx on Laoben and use webbench to simulate 10,000 static file requests. Apache has good support for languages such as php. In addition, apache has a strong support network and has been developed for a longer period of time than nginx. Reverse proxy server 2. Nginx supports 7-layer load balancing; of course, Nginx may be better than other
Apache supports higher concurrency, but according to NetCraft statistics, in April 2011, Apache still accounted for 62.71%, while Nginx was 7.35%. Therefore, in general, Aapche is still the first choice for most companies because of its The mature technology and development community already have very good performance. 12. Your needs for web server determine your choice. Big
In some cases, nginx is better than APACHE, such as static file processing, PHP-CGI support, reverse proxy function, front-end Cache, maintaining connections, etc. exist
In Apache+PHP (prefork) mode, if PHP processing is slow or the front-end pressure is high, it is easy for the number of Apache processes to surge, resulting in a denial of service. 13. You can take a look at the nginx lua module: https://github.com/chaoslaw...apache has more modules than nginx, and can be implemented directly with lua. Apache is the most popular, why? Most people are too lazy to update to nginx or learn new things 14. For nginx, I like it The configuration file is very concisely written. Regular configuration makes many things simple. It runs efficiently, takes up less resources, and proxy It has powerful functions and is very suitable for front-end response servers. 13. Apache has advantages in processing dynamics. Nginx has better concurrency and low CPU memory usage. If rewrite is frequent, then Apache is the best choice
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the comparison between Apache and ngnix, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.