On the Tumblr engineering blog a post about PHP 7 at Tumblr, and how the migration from PHP5 to PHP7 boosted the performance of Tumblr. The project started as a Hackday in 2015, and at that time not all extensions supported PHP7 but it still works ! Then the real work started this spring as things goes more stable, the migration finished in August where all production servers was updated.
An interesting tool that helped in the migration is Phan, it helped finding code in the codebase that would be incompatible with PHP 7. Of course, in addition to a suite of unit and integration tests.
The CPU load on the servers decrease at least 50%
The performance was noticed immediately after the migration, the latency was dropped by half and the CPU load on the servers decrease at least 50%, often more.
PHP 7 also brings a lot of fun new features that can make the life of the developers at Tumblr a bit easier. Some highlights are:
- Scalar type hints: PHP has historically been fairly poor for type safety, PHP 7 introduces scalar type hints which ensures values passed around conform to specific types (string, bool, int, float, etc).
- Return type declarations: Now, with PHP 7, functions can have explicit return types that the language will enforce. This reduces the need for some boilerplate code and manually checking the return values from functions.
- Anonymous classes: Much like anonymous functions (closures), anonymous classes are constructed at runtime and can simulate a class, conforming to interfaces and even extending other classes. These are great for utility objects like logging classes and useful in unit tests.
- Various security & performance enhancements across the board.
PHP 7 is pretty rad! and congratulation to Tumblr team and to the PHP community !