This website uses cookies to enhance your browsing experience. By continuing to use this website, you agree to our use of cookies. Click here to learn more, including how you can manage your cookie preferences.


Announcing: Kaltura support for PHP7


PHP 7 was officially released by the PHP team on Dec 3rd, 2015.
This post is meant to be a general guide for people who wish to know what PHP 7 is about and what to expect when porting their code from PHP 5.5 to PHP 7, as well as a technical description of our experiences when porting to PHP7 and building and packaging our own deb packages to provide it.
It is important to note that while these packages were created to fill the Kaltura server needs, they can be used by any other project that needs PHP 7 and do not depend on Kaltura’s software in any way.
They are publicly available from our repo here:
deb [arch=amd64] kajam main
And, for those who are interested, the original spec files for the deb build are also available:
Now, without further ado, let us dive into the tech stuff…

Why PHP 7?

The best reason for upgrading to PHP 7 is its performance, brought primarily with the changes introduced as phpng.
All values in existing Zend Engine implementation were allocated on the heap and they were subject for reference counting and garbage collection. Zend engine mostly operated by pointers to zvals (in many places even by pointers to pointers to zval).
The new implementation operates by zval structures themselves. It stores new zval structures directly on VM stack, in HashTable buckets and property slots.
This dramatically reduces the number of heap allocations/deallocations and avoids reference counting and garbage collection on primitive values (null, bool, long, double, interned string, immutable arrays).
The new implementation uses more VM stack space (instead of heap), because now it keeps the zval structures there instead of using pointers.
You can read more about these modifications in the RFC proposal here: and also here:
In addition to performance, there should be substantial memory savings, as optimization of internal data structures is one of the primary ways in which performance improvements have been achieved.

Porting the Kaltura code base to PHP 7

Since we recently ported the code base from PHP 5_3 to PHP 5_5, not many additional changes were required for it to properly run on top of PHP 7.
The main areas which needed fixing were due to PHP 7 being more strict and so, code issues that up until now would result in a warning/notice are treated in PHP 7 as fatal.
This can, to a certain extent, be controlled by passing different error reporting values [] in the configuration INIs but we always use the default engine values when testing.

The following
changes were made in order to support PHP 7: – Methods with the same name as their class will not be constructors in a future version of PHP – getRootObjects() is not a static method – Declaration of Insertwidget::doSave(PropelPDO $con) should be compatible – preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
A good resource for deprecated functionality can be found here:

Packaging PHP 7

Kaltura server is available with both deb and RPM packages.
In order to support PHP 7, we created deb packages which we host on our repo.
RPM packages may follow but the reason why we started with debs is simply that the deb spec allows you to specify logical OR when defining dependencies and so, you can, for example, say:
Depends: php5-cli|kaltura-php7-cli
Because php5-cli is first, this would cause APT, when installing, to either install php5-cli, which is the official PHP 5 deb from the distro, or, consider the dependency as fulfilled in the event kaltura-php7-cli is installed.
That means that the kaltura deb spec files only required a small change in order to support work with either stack: all that needed to change was adding this logical OR where ever a PHP package is required. In order to install using PHP7, all one needs to do is first install the kaltura-php7 deb package and the proceed to install Kaltura CE as normal.
For RPM, alas, defining logical OR dependencies is not possible, one can only define the package as providing ‘php’ and then declare another package as depending on ‘php’, which is not ideal enough for our case. Nonetheless, if there’s enough requirement, we will provide PHP7 RPMs as well.

Available Kaltura PHP 7 packages
kaltura-php7 - Meta package that installs all needed PHP deps in order to run the Kaltura server
kaltura-libapache2-mod-php7 - PHP 7 Apache module
kaltura-php7-apcu - APC User Cache for PHP 7
kaltura-php7-cli - command-line interpreter for the kaltura-php7
kaltura-php7-curl - CURL module for kaltura-php7
kaltura-php7-dbg - Debug symbols for PHP7
kaltura-php7-dev - Files for PHP7 module development
kaltura-php7-gd - GD module for kaltura-php7
kaltura-php7-gmp - GMP module for kaltura-php7
kaltura-php7-intl - internationalisation module for kaltura-php7
kaltura-php7-ldap - LDAP module for kaltura-php7
kaltura-php7-mcrypt - MCrypt module for kaltura-php7
kaltura-php7-memcache - memcache extension module for PHP7
kaltura-php7-mysql - MySQL module for kaltura-php7
kaltura-php7-mysqlnd - MySQL module for kaltura-php7 (Native Driver)
kaltura-php7-odbc - ODBC module for kaltura-php7
kaltura-php7-opcache - Opcache module for kaltura-php7
kaltura-php7-pgsql - PostgreSQL module for kaltura-php7
kaltura-php7-pspell - pspell module for kaltura-php7
kaltura-php7-recode - recode module for kaltura-php7
kaltura-php7-snmp - SNMP module for kaltura-php7
kaltura-php7-sqlite - SQLite module for kaltura-php7
kaltura-php7-ssh2 - PHP Bindings for libssh2
kaltura-php7-tidy - tidy module for kaltura-php7
kaltura-php7-xmlrpc - XML-RPC module for kaltura-php7
kaltura-php7-xsl - XSL module for kaltura-php7

Toggling between PHP stacks

Since the kaltura-php7 packages install onto a different prefix [/opt/kaltura] than the distro’s packages [/usr], both stacks can co-exist on the machine and are not conflicting.
When installing the kaltura-php7-cli package, update-alternatives is being executed during the postinst phase, setting /opt/kaltura/bin/php7 to be the default PHP CLI, the php5 CLI binary provided by the php5-cli deb is still available at /usr/bin/php5 however.
For the PHP Apache module, the kaltura-libapache2-mod-php7 postinst calls:
a2dismod php5
a2enmod php7

You always toggle between the versions by running these commands and reloading the Apache.

Building additional extensions using the Kaltura PHP stack

– Install kaltura-php7-dev
– Call /opt/kaltura/bin/phpize
– If you have more than one PHP installation on your machine, when running configure, pass –with-php-config=/opt/kaltura/bin/php-config
– Continue as usual with make && make test && make install

A simple benchmark

At Kaltura, we use Sphinx [] which is a full-text search server to offload our operational MySQL DB.
This is done to achieve better performance when making queries on our data.
For a benchmark, we chose to test a simple CLI script [] which we often use the reindex the Kaltura entries from the MySQL to Sphinx.
The script uses Propel [] to select all entries that are in status READY and then updates their metadata on the Sphinx server.
Running it 100 times on an Ubuntu 14.04.2 machine, with a DB of 1664 entries, the average runtime with the default PHP 5.5.9-1ubuntu4.14 stack supplied by Ubuntu’s official repo, was:
real 33.014s
user 24.2571s
sys .8743s

And with the parallel Kaltura PHP 7 stack:
real 17.5481s
user 9.6783s
sys .7153s

With such benchmarks, it is always important to note that:
– The same PHP and Zend extensions were loaded in both cases
– Both tests were done on the same machine, while it was performing the same, additional routine operations
– This is a lab machine and so, it does not accept outside requests so temporary peaks are not an issue
Now, THAT is a nice performance gain:)

Additional helpful resources

Additional PECL extensions

The Kaltura server makes use of the Memcache and SSH2 PHP extensions. At the time of writing this post, no official port has been released for Memcahce on, however, Szabolcs Balogh has done a great job porting memcache here:
For SSH2, we’ve used Sean DuBois port here:
Which recently also got merged back to the official repo, see:

Call for testers

The Kaltura PHP 7 stack is released as beta and we would like to request your help in testing it.
In order to install the Kaltura Server with PHP 7, please follow:
Bug reports should be submitted as GitHub issues on the platform-install-packages repo.
Thank you!

Let's Get Going