PHP 7 is here!

Posted in PHP by

PHP 7 is here

PHP 7 has been released! That’s right, PHP 5.6 has given way to PHP 7.0 (stop, do not pass PHP 6, do not collect $200)! The new version is now available on all WebFaction servers. So let’s take a look at some of the biggest changes in PHP 7.

Performance

Perhaps the most talked about part of PHP 7 is the substantial improvement in performance and memory usage. Measuring requests per second, benchmarks with PHP 7 have shown 30 to over 100 percent improvements over PHP 5.6. You read that correctly: upgrading to PHP 7 can sometimes double the performance of an application. The PHP project achieved these gains by merging the changes of PHPNG into the main PHP project. Although memory benchmarks are harder to come by, anecdotal reports are that PHP 7 uses less memory as well. While the real-world performance gains of upgrading to PHP 7 vary by application, you should expect to experience a marked improvement.

Spaceships

PHP 7 comes with a spaceship, or at least it comes with an operator that looks like a spaceship: <=>. The spaceship operator, more formally known as the “combined comparison” operator or “three-way comparison” operator, makes it easier to write comparisons for sorting. The spaceship operator compares two values and evaluates to 1, -1, or 0, if the first value is greater, less than, or equal to the second value, respectively.

Take the expression a <=> b, for example. If a is greater than b, then the expression evaluates to 1. But if a is less than b, then the expression evaluates to -1. If a and b are equal, the expression evaluates to 0. In this way, the spaceship operator reduces a complex ternary expression like ($a < $b) ? -1 : (($a > $b) ? 1 : 0) to just a <=> b.

Plus spaceships are cool. Pew pew!

Type hints

PHP 7 expands the language’s type hinting features. Previous versions of PHP supported limited argument type hinting. PHP 7 adds scalar type hinting to arguments, so you can hint int, float, string and bool for argument types. What’s more, PHP 7 lets you declare what type a function is expected to return, including the scalar types.

But there’s a catch

With these changes, you may be eager to upgrade, but keep in mind that PHP 7 is not a drop-in replacement for PHP 5.6. Many long-deprecated SAPIs and functions have been removed. There have been changes to errors and exceptions, variable handling, and source parsing too numerous to list here.

We recommend that you read the official guide on Migrating from PHP 5.6.x to PHP 7.0.x or see the the official ChangeLog to learn about every change and how it may affect your application. We also recommend that you test your application before upgrading your live site.

When you are ready to upgrade, you’ll find PHP 7 available in our one-click installer and on the command line as php70.

-
-

PHP-5.4 is here

Posted in PHP by

Things certainly move fast on the web. Just a few weeks ago we described our PHP setup on this blog and we proudly explained that we had both PHP 5.2 and 5.3 installed on our servers. But now that blog post is obsolete because PHP 5.4 was just released!
Fortunately we’ve already installed PHP 5.4 on all of our servers, just days after it was released:

[remi@web300 ~]# php54 -v
PHP 5.4.0 (cli) (built: Mar  2 2012 06:58:40)

We’ve also added a new Static/CGI/PHP-5.4 to our control panel for the early adopters.
If you want to switch an existing PHP app to PHP-5.4 you can do so by putting this in a .htaccess file:

<FilesMatch .php$>
    SetHandler php54-cgi
</FilesMatch>

Amongst many other improvements PHP-5.4 is faster and uses less memory and it provides a new feature called Traits which enables developers to reuse code.
More details are available in the ChangeLog.

-
-

New PHP-5.3 app available

Posted in PHP by

We’ve just added a new app to our control panel called “Static/CGI/PHP-5.3”.

This means that you can now choose between PHP-5.2 and PHP-5.3 when you create a PHP app.

The PHP-5.3 command line tools are also installed on all servers:

[remi@web180 ~]$ php53 -v
PHP 5.3.5 (cli) (built: Mar 15 2011 06:04:49)
[...]

[remi@web180 ~]$ php -v
PHP 5.2.11 (cli) (built: Oct 18 2010 14:11:48)
[...]

Enjoy!

PS: Note that the PHP-5.3 app is only available on Web120 and over. This is because machines before that use mod_php to serve PHP apps and Apache can’t run mod_php-5.2 and mod_php-5.3 side by side. If you’re on a machine before that and want to run PHP-5.3 you can either build your own Apache/PHP-5.3 stack or ask for a plan on a newer server. Open a ticket and we’ll be happy to help.

Update May 12th: The PHP-5.3 app is now available on all servers.

-
-