PHP 7 now available on Scalingo

August 05, 2016 - 5 min read
PHP 7 now available on Scalingo

We’re a little bit late to the party but we have some great news for the PHP developers out there: PHP 7 support is now publicly available on Scalingo! From now on, you can execute a PHP 7 application in an instant.

Enabling PHP 7 for Your App

Getting your application executed by the powerful PHP 7 is as simple as specifying it in your Composer file. The important key in this JSON file is require:

{
  "name": "my-php7-app",
  "require": {
    "php": ">=7.0"
  }
}

We use our semver webservice to solve the required version.

If you already have an application running, just update your existing composer.json file with a newer version. Then, git commit and git push this change.

An Example of PHP 7 App

In order to start a PHP 7 application, you first need to write a simple PHP code. For this example, we will just show a simple phpinfo page. The index.php file is:

<?php phpinfo();

Then we need to specify the composer.json. The simplest one would be:

{
  "name": "php7-support",
  "require": {
    "php": ">=7.0"
  }
}

Next we must generate the composer.lock file. We can install composer locally and generate this last file with:

php composer.phar install

Eventually create a Scalingo application, commit and push your files:

scalingo create appname
git remote add scalingo git@scalingo.com:appname.git
git add index.php composer.{json,lock}
git ci -m "Test PHP 7 support"
git push scalingo master

This application is now available online at appname.scalingo.io:

Screenshot of the PHP7 sample

What’s New in PHP 7

Improved Performance

The most awaited change in PHP 7 is the use of the new Zend Engine 3 which provide better performance. Indeed, this new version is twice as fast as the Zend Engine used in PHP 5.6. More performance improvement will be more easily achieved in the future thanks to a better code organization for a migration towards a just-in-time compiler.

Do not be afraid anymore to use the assert construct when you develop a new code. The new assert has zero cost when in production. More information on thisin the documentation.

Enhancement for the developers

Return Type Declaration

PHP now provides a way to specify a type for the return value. Be aware that the behavior changes depending on the strict typing mode you use. More information on this in the documentation.

Anonymous Class

Support for anonymous classes was added in PHP 7. This simple syntactic sugar add a very convenient way to create simple one-off objects. More information on this in the documentation.

Improved Exceptions

In older PHP versions, handling fatal error use to be nearly impossible. In production, such an error results in a blank screen for the client. In PHP 7, an exception is thrown rather than just stopping the script. Some unrecoverable errors still exist such as out of memory.

To develop this feature, a newThrowable interface becomes the common ancestor for both Error and Exception.

Much more things

Much more new wonderful things were released in this version such as new operators, easier to use Cryptographically Secure PseudoRandom Number Generator (CSPRNG)… Read the full blog post andchangelog for a comprehensive list of novelties.

Available extensions on Scalingo

The following extensions have been upgraded on the process:

  • APCu with v5.1.4
  • imagick with v3.4.1
  • mongo with v1.1.7

When not to use PHP 7

PHP 7 being a recent version, some extensions do not work yet. You should not use this version if you need one of these extensions:

Share the article
Étienne Michon
Étienne Michon
Étienne Michon is one of the first employee at Scalingo. With a PhD in computer science Étienne takes care of Research and Development at Scalingo. He also regularly contributes to this blog with technical articles.

Try Scalingo for free

30-day free trial / No credit card required / Hosted in Europe