There is a lot of interesting things going on in the Moodle & PHP worlds recently – Moodle 3.0 has just been released and PHP 7 release is coming soon. Among other things, PHP 7 promises a great performance improvement over PHP 5.6 – PHP 7 is supposedly up to 2 x faster.
We have decided to put that into the test by simulating real-world Moodle 3.0 usage scenario. After a quick Moodle PHP 7 bug fix and hack to ignore Moodle version check, we were able to install Moodle using PHP 7.
The environment used for testing:
- Moodle: 3.0rc4 (Build: 20151113)
- PHP: Version 7.0.1-dev with Zend OPcache v7.0.6-dev vs PHP Version 5.5.9 with Zend OPcache v7.0.3 (Ubuntu 14.04 packaged version)
- OS: 64 bit Ubuntu 14.04
- Mysql server 5.5
- Physical machine with:
- 16GB RAM
- one 2GHz i7-2630QM CPU (4 cores, 8 threads)
- SSD hard drive
The test was performed with jmeter running on the same machine. This has affected the performance of the system but it should be the same overhead for running both PHP versions, so it should not matter for the comparison. We have tested 200 users answering 100 quiz questions each. Each user had a separate account and started his run by login, followed by answering 100 questions and submitting the quiz. Every question was on a separate page, so each user generated over 200 page hits. The test was set up to run 20 threads in parallel. The timings are taken from jmeter statistics and from Moodle performance reporting (MDL_PERF). After switching PHP version we have run & discarded dozens of jmeter tests to warm up all caches. All tests were executed with opcache enabled.
The results are grouped by PHP script that was run and show:
- the times it took to execute each PHP script (with minimum time, maximum, average and standard deviation) measured in seconds
- values like above for CPU time (the time that CPU has spent working on each request) in seconds
- memory used shown in MB
The most relevant values for a comparison like this are CPU time and memory used, so let’s see how well did PHP 7 do compared to PHP 5.
PHP 5.5 results
PHP 7 results
PHP 5.5 vs 7
The table below show how much % of time / memory was consumed by PHP 7 compared to PHP 5.5.
In summary, PHP 7 performed more than 2 time faster compared to PHP 5.5 while consuming only 60% of the memory that PHP 5.5 did. Statistics from jMeter confirm that – PHP 5.5 was able to process on average 10 requests per second, while PHP 7 20 requests/second.
Keep in mind that the above does not mean that your users will get this kind of performance improvement as soon as you switch to new PHP version. The time measured here is a CPU time on the server side, which is just a fraction of the whole time needed to render the page for end user. Once you add network latency, loading media and rendering the page by the browser – the end result will be much less spectacular. Having said that the results are quite impressive – go PHP 7!