This benchmark is a quick test to confirm (or not!) what benchmarks on the internet report lately: PHP 7.0 performs better than its predecessors.
Recently I received an email pointing me to this article and with a request that I conduct a test of Nginx, which should supposedly be a better web serving application. But in previously mentioned article they state they are getting over a 500% more from the same hardware with a new piece of software, is still awesome. From the experience I know that with such claims, one must utilise some healthy skepticism.
Here you are able to see an overhead which each PHP request imposes. Interesting and not unexpected is a fact that Apache performs better at this test, much better. The reason here is that Apache has PHP processing "built-in" via mod_php module. On the other hand Nginx proxies PHP requests to another application server (php-fpm). The performance of Nginx in the graph above is roughly half of that of Apache, which can easily be explained with "two servers doing the work of one". A reader must mind that here almost no PHP processing is done, a simple echo statement only.
At this test Apache starts to lag behind. Nginx perform better without keepalive feature, but with keepalive enabled it outperforms Apache by more than a factor of 2. This test is here only to demonstrate the overhead of static file serving.
Here we start the real static file serving benchmark. With file size of 100KB we come closer to what one might call "real world benchmark". Again we are able to demonstrate that Nginx without keepalive feature performs on-par with Apache with keepalive feature enabled. But Nginx with keepalive feature enabled outperforms Apache by factor of 2. The throughput we may calculate here is roughly around 1,2GB/s, but mind that all tests utilise loopback network interface.
Again "real world static file serving benchmark", yet this time with a file size of 1MB and without keepalive feature (keepalive does not matter anymore as majority of time is spent by transfering data and not by TCP overhead of establishing new connection).
Here you can see Nginx has a slight edge, but I must note that Apache had a .htaccess parsing enabled (AllowOverride All directive), a feature that Nginx is lacking. A drop in performance at the high concurrency levels has probably resulted from too few concurent database connections available to the system.
Note how close to the static file serving comes dynamic echoing the same content from PHP script.
Nginx difference in static vs dynamic overhead is notably larger.
If memory usage is of real importance to you, then you should seriously consider using Nginx. With nginx all the static file serving capabilities can be achieved by using only that many worker processes as there are CPU cores on your server. In the example above this means 8 cores and 8 worker processes for Nginx, no matter how many clients connect to it simultaneously. For PHP, there are 16 php-fpm workers alive in the example above (which is enought if you are not doing some blocking IO). When you sum this up you get a decently low memory usage.
On the other hand Apache (with prefork MPM, which is required by mod_php) creates as many processes as there are clients (up to the limit of MaxClients directive) and it does not matter whether clients are requesting static files or for PHP applications. So for 200 clients it will create 200 processes with embedded PHP, which gives far larger memory footprint than Nginx has.
Short answer: I do not know.
If you host many websites and users utilise .htaccess files and change them frequently, then the answer is probably "no". The cost of switching over to Nginx and converting all the configuration to new format usually reaches the cost of buying another server.
If you have single application on multiple servers and most of the processing power is not consumed by serving static file content, the answer is also probably "no".
If you are mainly serving static content, the answer is obviously "yes".
If you are consolidating services with some virtualization technology, then answer is probably "yes", as Nginx tends to have smaller memory footprint than Apache.
If you are looking towards Nginx as your PHP server optimization, look again, but not at Nginx, at your application code.
I hope that this comparison helps you with your decision. If you have some questions, feel free to email me or post a comment below.
NCONC is the number of concurrent requests, as noted in the graphs.
Each test was repeaded 5 times and the average was calculated.
Thanks to Sean Osh for requesting this info.
David pointed out in comments below that php-fpm had max children setting set to 16, which is far less than what Apache had. Currently re-testing everything with the same software (OpenSSL 0.9.8 anyone?:) on the same hardware would require too much resources/work or to put it plainly – it is downright impossible for me ATM.
But: if a diligent reader does it properly, publishes the results and notifies me with URL, I will gladly include that URL in this article.