Avoid bottleneck... with PHP7

Who am I to speak such term ?

My name is Kevin Nadin - @kevinjhappy

I work at Darkmira, a company full of good guys like you, and you, and.... hum not you...
I'm a backend developer using PHP / Zend Framework

My dream is to rule the world, and so should be yours

  • Small ESN that promote industrialization and security
  • Sponsor in PHP ecosystems
  • Organize the Darkmira Tour in Brazil, biggest PHP community event in this country
  • We are looking for new talents ;)

PHP 5 to PHP 7 ?

This can boost up your website, payment transactions and API requests

"How Badoo save 1M $ passing PHP 7"

  • Link to the blog
  • PHP7 reduce the number of small memory allocations
  • OpCache simplify way better from source code
  • Process time was cut in half, which improved overall response time by a little more than 40%

And then ?

  • 100% performance gain

  • Lower memory usages

  • So, by cutting CPU Usages by half

  • 600 servers for Badoo => 300 servers, therefore 1M$ of saving (4k each + 100k hosting per year)

  • Bonus: the cloud also have a boost perf !

I don't believe it...
Show me some benchs !!

PHP 5.6.30

test_ifelse : 0.354 s

test_math : 0.918 s

test_loops : 0.624 s

test_stringmanipulation : 0.874 s

PHP 7.0.15

test_ifelse : 0.167 s

test_math : 0.247 s

test_loops : 0.210 s

test_stringmanipulation : 0.319 s

And it's still increasing...

Save the planet !

Whaaaaat ?

  • Around 2 billion sites on the web
  • On 10 million physical machines
  • PHP drives at least 50% of them

PHP7 exist in production ?

  • Only 5% of website

  • not even a 1/4 million servers

In Earth point of view

  • 3000 Kwh/year per server cost approximatively 400€
  • And don't forget about cooling those servers
  • 0.5kg CO2 per KWH

5% of PHP7 server represents...

  • 200M€ savings
  • 750M KWH Savings
  • 375M kg less CO2

If all server worked with PHP7

  • 4B € savings
  • 15B KWH savings
  • 7.5B kg less CO2

Save
the
Planet...

Upgrade
to
PHP7 !

Do you see how cute Iam ?
Don't you want to save me?

Earth is thanking you !

This message is powered by ©The Earth Ltd.

Yeah,
Easy for the prod!
And for the devs?

Most common problem:
PHP5.x applications have Legacy code

What is Legacy ?

Legacy stand for :
"Old and unmaintainable code we keep because it works and provides 90% of the company revenue"

Love this tweet :D

Preparing legacy apps for PHP 7

Phan: static code analyser

  • Developed by Etsy, set some checks
  • PHP7/PHP5 backward compatibility
  • unused/dead/unreachable code search
  • read phpdoc type annotation
  • and a lot of other stuff
  • check github phan/phan
// PHP 5.6

$dbConnect = mysql_connect('HOST', 'USER', 'PASS');

mysql_query($request);


// in PHP 7 it is deprecated

$dbConnect = mysqli_connect('HOST', 'USER', 'PASS');

mysqli_query($dbConnect, $request);

//don't forget to add $dbConnect as first parameter of mysqli functions

My tips: mysql_connect... no more !

Lot of include !

Centralise them in .include/ directory

// PHP 5.6 without Autoloader
// Using the Excel library php_writeexcel

require_once "../.include/php_writeexcel/class.writeexcel_workbook.inc.php";
require_once "../.include/php_writeexcel/class.writeexcel_worksheet.inc.php";
require_once "../.include/php_writeexcel/class.writeexcel_workbookbig.inc.php";

$workbook = new writeexcel_workbookbig($filename);


// in PHP 7 php_writeexcel doesn't work
// and still no autoloader

// Migrating to Excel library Box/Spout

require_once '../.include/spout/src/Spout/Autoloader/autoload.php';

$writer = WriterFactory::create(Type::XLSX);

Check for compatibility on Library

Can we add Autoloader ??

Composer can be installed on Legacy without today's code structure using classmap

It can load all .php and .inc files it will find

And after ?

  • The rest to do can be very easy, give it a try
  • Passing from PHP 5.3 to PHP 7.1 internal tools took me only one day of development in a previous company
  • As for the production, making a pre-prod of this old server in PHP 7.1 did take less than one hour

Try it !
It will be fun :)

Yes, I assure you !
I do !
I think...

...
Yeah it is great :)

And do I have to remind you why ?

A great book to read about :

(I'm not paid to say this so you can trust me)

Supported versions 

  • PHP 5.3 to 5.5 are EOL
  • PHP 5.6 and 7.0 are on security fixes
  • PHP 7.1 and 7.2 have active support

You are not using PHP ?

Silly right ? We are in a PHP user meetup...
Still be careful of web language End of Life date

PHP 7.2 ?

  • Is now out in case you're wandering ;)
  • Symfony 4 is also out
  • Zend Expressive 3.0 is on alpha
  • Get ready for PHP 7.2 !

PHP 7.3 ?

No new features announced but a big performance improvement with a new level of OpCache optimization

function fn(int $x) {
    return 2;
}

Rewrite to :

NB: If you want to rewrite all of your Legacy code

NB2: And if you like my beautiful voice ;)

Please add a Youtube view at my talk :D

La génération de dates en PHP -
Kevin Nadin - Forum PHP 2017

Thank you !

Made with Slides.com