In view of the forum members of Nginx, Apache and their respective ways to run PHP performance questions, I reproduced from abroad and translated an article and post a point of their own views, I hope to be helpful.
Original: http://blog.a2o.si/2009/06/24/apache-mod_php-compared-to-nginx-php-fpm/
All the software is compiled from the source code (see below). Test tool using Apache Apachebench (AB), the following results are tested on the same machine, all servo systems (Nginx, Apache) are turned off the logging function (to prevent the impact on performance), the test process keepalive is configured to be enabled, Once disabled, each test is tested 5 times, and then the average is obtained. The test files are as follows:
Helloworld.php? Short output "Hello, world!" PHP script (bytes) that represents the cost of the PHP file test process, compared to the static file below
HelloWorld.txt? A static file, output "Hello, world!" (same as bytes), used to represent the overhead of a static file testing process
100KB.txt? A static 100KB size file
1MB.txt? A static 1MB size file
Index.php? A PHP file that contains multiple complex processes, including database queries, file cache reads, and template [compile] processing.
Hardware environment
Hardware: HP DL380 G5
Hardware cpu:2x Intel Xeon E5420 (4 cores each, total of 8 cores)
Hardware memory: 8GB of ECC RAM
Hardware disk: Smart Array p400i RAID-1 with 2x 147GB SAS drives
Operating system: Slackware 12.2 With almost all software compiled from source
File system: Ext3
Apache version: 2.2.11, PHP run by mod_php mode
Nginx version: 0.7.59, PHP by PHP-FPM (run by socket)
PHP version: 5.2.9
Eaccelerator version: 0.9.5.3 (for both, Apache and Nginx)
MySQL version: 5.0.77
OpenSSL version: 0.9.8k
Service logs, request logs are disabled
Apache Compilation options:
Apache mod_php:httpd.conf Http://blog.a2o.si/wp-content/uploads/2009/06/httpd.conf.txt
Apache Mod_php:php.ini Http://blog.a2o.si/wp-content/uploads/2009/06/php.ini.txt
Nginx php-fpm:nginx.conf Http://blog.a2o.si/wp-content/uploads/2009/06/nginx.conf.txt
Nginx php-fpm:php-fpm.conf Http://blog.a2o.si/wp-content/uploads/2009/06/php-fpm.conf.txt
Nginx Php-fpm:php.ini the same way as mod_php
Test results:
helloworld.php
Here you can see the overhead that each PHP request imposes. Interestingly, one fact is that Apache performs better in this test and is much nicer. The reason here is that Apache PHP is "built-in" via mod_php, and the module is processed. On the other hand Nginx proxy PHP requests to another application server (PHP-FPM). The performance of Nginx in the above figure is about half of Apache, easy to explain. PHP Here is just a simple output string.
[font= ' Lucida Grande ', Verdana, Arial, Sans-serif] HelloWorld.txt
[font= ' Lucida Grande ', Verdana, Arial, Sans-serif]
[font= ' Lucida Grande ', Verdana, Arial, Sans-serif]
[font= ' Lucida Grande ', Verdana, Arial, Sans-serif]
In this test the Apache began to lag behind. Nginx performance exceeds twice times the performance of Apache. This test is a demonstration of the overhead of a static file service.
[font= ' Lucida Grande ', Verdana, Arial, Sans-serif]100kb.txt
[font= ' Lucida Grande ', Verdana, Arial, Sans-serif]
[font= ' Lucida Grande ', Verdana, Arial, Sans-serif]
Here the test has been close to the static files in the production application (100KB), and we can prove that Nginx disabled keepalive after the keepalive pressure found with Apache is still better than Apache about twice times. The throughput of this test was about 1.2gb/s, but none of the tests were actually out of the internet (the test was done on a local area network).
[font= ' Lucida Grande ', Verdana, Arial, Sans-serif]1mb.txt
This test does not have all servos open keep alive, each request to establish a new connection, but compared to the data transfer, the cost of the new connection does not matter.
PHP program in real Sense:
You may be surprised to see that Apache runs a real, complex PHP program with less performance than Nginx.
But the original author may not notice, NGINX PHP at this time there must be a lot of play back wrong (and the author did not open the log, after the test did not verify)
In the original, the author only says:
Apache Open. htaccess (Nginx does not have this feature) can result in degraded performance of the connected database.
There are two more tests behind it (comparing Apache's ability to handle static and self-handling dynamics and Nginx, respectively). I'm not here to translate.
Summarize:
Apache is less capable of handling static than Nginx, but Nginx is less stable than Apache mod_php.
What if it's a complement?
Nginx do the front end, Apache do backend. Nginx Proxy_pass Apache, then two servo doc_root are paired together, and let the static file directly let Nginx output, only forward PHP request to the backend Apache processing.
There are members of the question: Two servo, is simply superfluous.
Answer: My goal is to have a stable and balanced high carrying capacity. Instead of taking one.
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.