Skip to content

Moodle and PHP7... Are we there yet?

2015-10-14

by Matt Porritt

Moodle is an Open Source Learning Management System (LMS), used by educational and corporate entities worldwide. At Catalyst, we manage Moodle instances for organisations ranging from small sports clubs with a handful of users, to universities and corporates with 100,000+ users.

PHP is the programming language that Moodle is written in; it is known as a Server Side Scripting Language. It is also a large part of the platform responsible for delivering Moodle to your web browser. More or less it works like this (Computer Science teachers look away now): when you go to a page in a Moodle instance, a request is sent to the web server asking for the content on that page. This request is then sent to PHP. The PHP process retrieves the file/s needed to return the content you want. These files are compiled, executed and the result, delivered back to the web server.

The version of PHP used with Moodle is important. Newer features of Moodle won't work on older versions of PHP and to some extent the reverse is true. The latest version of PHP, PHP7, is due for release in November 2015 and Release Candidate 4 (RC4) is now available.

Why PHP7?

There are many new features in PHP7, including spaceships! (Seriously, check it out here: https://www.zend.com/en/resources/php-7). However, the main improvement this blog post is concerned with, is speed. The faster that PHP can read, compile and return the result of a request to the web server, the faster a Moodle page will load (which your learners care about) and the more requests your web hosting infrastructure can handle in a given time period (which your system administrators care about).

According to the people responsible for it, PHP7 is between 25% - 70% faster than PHP5.6 (the current latest stable version). The ability to make your web application roughly 70% faster simply by updating a (free) piece of software is a big deal.

How fast is it?

Not wanting to take it at face value, we tested the speed difference for ourselves.

The tests used Apache Benchmark to request the "My Home" page of a Moodle 2.9 instance 10,000 times using 20 concurrent threads. For the tests we also disabled Operational Code Caching (opcache). This is by no means reflective of a real world use case for Moodle, but for this test we just wanted to see the performance difference that PHP7 may deliver over PHP 5.6 in the request, compile, return cycle. The only difference between tests runs was the version of PHP.

PHP7 test results

The graphs above clearly show a performance increase for PHP7. PHP7 completed the 10,000 requests 12% faster than PHP5.6. With 95% of requests taking 16% less time to complete with PHP7.

These basic tests don't hit the 25% speed improvement touted and it is a long way off 70% faster. However, achieving a 16% performance improvement is still a very good increase for a web application.

All aboard for PHP7?

So PHP7 is indeed faster. Should we be all making the move to PHP7 for Moodle? Well no, at least not quite yet...

Moodle did run when PHP7 was installed on the test rig used to get the results above. You can log in click around and even set up Moodle Universal Caching (MUC), however, it is not all smooth sailing, as running the unit test suite for Moodle revealed.

It took a couple of minor changes to the code to get the Moodle 2.9 unit test suite to run under PHP7. Once running, the test suite failed due to fatal errors at 12% test completion. Before the unit tests suite stopped, 488 of the 3,992 tests had run with 7 errors. The rest passed.

While the unit test result only goes a little way to give a full indication of how much work needs to be done, it does show that PHP7 won't be a drop in replacement for systems running Moodle just yet.

We have been given an exciting taste of what is to come, these basic tests show a good improvement, providing a base for future testing and analysis. Stay tuned there will be more updates as Catalyst continues the journey with PHP7 and Moodle.

Matt Porritt is a Solution Architect based in our Melbourne, AU office.