0

I'm benchmarking these two setups (installed on the same system)

nginx 1.8.0 + php-fpm (5.6.14-0+deb8u1)
apache 2.4.10 + mod_php (5.6.14-0+deb8u1)

Have runned through the output of phpinfo() and they look the same (haven't changed anything manually)

Hardware:

Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz + 16GB RAM

Test 1 - one single HTTP (PHP) request once (no concurrency)

nginx ~= 360ms
apache ~= 320ms

Test 2 - loading the website with all static content css/js etc

nginx ~= 7.7sec
apache ~= 8.9sec

What is it that I have missed in the configuration?

AllowOverride All is even set on apache and apache still outperform nginx on a PHP request!?

nginx

user  www-data;
worker_processes  8;
pid  /run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    sendfile  on;
    tcp_nopush  on;
    tcp_nodelay  on;
    keepalive_timeout  65;

    server_tokens  off;
    autoindex  off;

    include  /etc/nginx/mime.types;
    default_type  application/octet-stream;

    access_log  /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log warn;

    index  index.php index.html index.htm;

    gzip  on;

    server {
        listen  80;
        server_name  domain.com;

        root  /var/www/public/secure;

        access_log  /var/log/nginx/access.log;

        # Add trailing slash
        rewrite  ^([^.\?]*[^/])$ $1/ permanent;

        location / {
            try_files  $uri $uri/ @missing;
        }

        location @missing {
            rewrite  ^ /index.php;
        }

        location ~ .php$ {
            include  /var/ini/nginx/fastcgi.conf;
            fastcgi_pass  php;
            fastcgi_param  SCRIPT_FILENAME /var/www/public/secure/index.php;
        }
    }
}

apache

Listen 8080

<Directory /var/www>
    Options -Indexes +FollowSymLinks
    AllowOverride All
</Directory>

NameVirtualHost *:8080

<VirtualHost *:8080>
    ServerName domain.com
    DocumentRoot /var/www/public/secure

    #LogLevel debug
    ErrorLog /var/www_log/error.log
    CustomLog /var/www_log/access.log common
</VirtualHost>
  • "Test 1 - one single HTTP (PHP) request once (no concurrency)" - this test is mostly irrelevant in practice. Test 50 simultaneous full page renders - you can quickly simulate it with curl or wget mirror. This is practical use. – kubanczyk Nov 21 '15 at 13:54
0

Outperform how? If this is set up like any other web request benchmark I've seen, then the lower the number, the higher the performance. In that second case, your nginx installation was over 1 second faster than apache. The second case is really the only one worth fussing over.

How many times are you running it for each benchmark?

Also, if you're getting 7.7 sec for one request on a phpinfo page, then that's concerning. What are the rest of the hardware specs? What OS? What other services are running?

  • the 7.7 sec is from you request the website until its fully loaded with all static content like js and css.. apache is 40ms faster than nginx with a PHP request.. and AllowOverride All is even enabled (.htaccsss) If AllowOverride All is disabled apache will be even faster – clarkk Nov 21 '15 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.