apache+php vs nginx+php performance evaluation (translated)

Source: Internet
Author: User
Tags apache php imap mysql version openssl version php script keep alive

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:

./configure–prefix=/usr/local/$PDESTDIR _httpd–sysconfdir=/etc/httpd \
–enable-authn-file–enable-authn-default \
–enable-authz-host–disable-authz-groupfile–enable-authz-user–enable-authz-default \
–enable-auth-basic \
–disable-include–disable-filter–disable-charset-lite \
–enable-log-config \
–ENABLE-ENV–ENABLE-SETENVIF \
–enable-ssl–with-ssl=/usr/local/openssl-$PVERSION _openssl \
–enable-http–enable-mime–enable-status \
–disable-autoindex–disable-asis \
–enable-info \
–enable-cgi–disable-cgid \
–enable-vhost-alias \
–disable-negotiation \
–enable-dir \
–disable-actions \
–disable-userdir \
–enable-info \
–enable-rewrite \
–ENABLE-SO \
–with-mpm=prefork

Nginx Compilation options:

./configure–prefix=/usr/local/$PDIR \
–conf-path=/etc/nginx/nginx.conf \
–error-log-path=/var/log/nginx/nginx_error.log \
–pid-path=/var/run/nginx.pid \
–lock-path=/var/run/nginx.lock \
–USER=HTTPD \
–GROUP=HTTPD \
–with-openssl=/usr/local/openssl-0.9.8k

PHP compilation options (mod_php running with Apache):

-–[these lines is for PHP with Apache (mod_php)] —————-
./configure–prefix=/usr/local/$PDESTDIR _httpd/$PDIR \
–with-apxs2=/usr/local/$PDESTDIR _httpd/bin/apxs–enable-cli–enable-cgi \
–WITH-CONFIG-FILE-PATH=/ETC/PHP/HTTPD \

Run with Nginx (PHP-FPM)
-–[these lines is for PHP with Nginx (PHP-FPM)] —————-
./CONFIGURE–PREFIX=/USR/LOCAL/PHP-FPM \
–ENABLE-CLI–ENABLE-FASTCGI–ENABLE-FPM \
–with-fpm-conf=/etc/php/php-fpm/php-fpm.conf \
–with-fpm-log=/var/log/php-fpm.log \
–with-fpm-pid=/var/run/php-fpm.pid \
–WITH-CONFIG-FILE-PATH=/ETC/PHP/PHP-FPM \

PHP Common Configuration
-–[these lines is common for both] —————-
–disable-short-tags \
–disable-ipv6 \
–disable-all \
\
–enable-libxml \
–with-openssl=/usr/local/openssl-$PVERSION _openssl \
–with-pcre-regex \
–with-zlib \
–WITH-BZ2 \
–with-curl–with-curlwrappers \
–enable-dba=shared–with-db4–enable-inifile–enable-flatfile \
–enable-dom–with-libxml-dir \
–enable-filter \
–ENABLE-FTP \
–with-gd–with-jpeg-dir–with-png-dir–with-freetype-dir \
–with-gettext \
–enable-hash–with-mcrypt \
–with-iconv=/usr/local/lib–with-iconv-dir=/usr/local/lib \
–with-imap=/usr/local/imap-$PVERSION _cyrusimap–with-imap-ssl \
–enable-json \
–enable-mbstring–enable-mbregex–enable-mbregex-backtrack \
–with-mysql=/usr/local/mysql-$PVERSION _mysql–with-mysqli=/usr/local/mysql-$PVERSION _mysql/bin/mysql_config \
–enable-pdo–with-pdo-mysql=/usr/local/mysql-$PVERSION _mysql–with-pdo-sqlite–enable-sqlite-utf8 \
–enable-reflection \
–ENABLE-SESSION–WITH-MM \
–ENABLE-SHMOP \
–enable-simplexml \
–ENABLE-SOAP \
–enable-sockets \
–ENABLE-SPL \
–with-regex \
–ENABLE-SYSVMSG–ENABLE-SYSVSEM–ENABLE-SYSVSHM \
–enable-tokenizer \
–enable-xml–enable-xmlreader–with-xmlrpc–enable-xmlwriter–with-xsl \
–enable-zip \
\
–with-pear \
–enable-zend-multibyte


Configuration document:



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.

apache+php vs nginx+php performance evaluation (translated)

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.