A small talk on the experiences gained from migrating from PHP 5.3 to 5.5.
View Slide
Glen Mailer
The Codebase
First commit April 2010 60k commits since
9300 PHP files 690k lines of codeAccording to git and cloc
10 releases a week 35 active committers 10 concurrent streams 1 deployable
The Platform
8 Test Environments 1 Staging Environment 2 Live Environments
74 Live PHP boxes
1300 req/s peak 500k uniques/week
Why?
Using basically the samePHP version as the firstcommitwith security patches
PHP 5.3 is dead
Bug fixes Performance
New Features!short array syntaxtraits$this in closuresyieldfinally
but no smoking gun
Bug #64827 GC causes segfaults
The Plan
Upgrade a dev box Support 5.3 and 5.5 Pass all tests Upgrade 1 Test env Upgrade CI Upgrade Test & Staging Incrementally Upgrade Live
Vagrant Chef Unit Tests Acceptance Tests
Hack hack hack...
3 days later
What changed?
APC becomes OPcache and APCu
Check for new function, fall back to old oneif (function_exists('opcache_reset')) {opcache_reset();} else {apc_clear_cache();}
“The PHP api will retaincompatibility with APC, aswill common configurationoptions, providing a dropin replacement.”APCu
Not a drop in replacement
APCu 4.0.1 APCu 4.0.2
No more mysql_
It will not be missed
preg_replace /e becomes preg_replace_callback
(string) array() Now raises a warningStill returns “Array”
Type-checked functionfunction inc($int) {if (!is_int($int)) {throw new InvalidArgumentException('Expected int, got: ' . $int);}return $int + 1;}
Unit test for type-checked function/*** @dataprovider provideIncInvalid*/function testIncRejectsInvalid($a) {try {inc($a);$this->fail('Expected exception');} catch (InvalidArgumentException $ex) {}}function provideIncInvalid() {return array(null, true, "string", array());}
Simplest fixthrow new InvalidArgumentException('Expected int, got: ' .json_encode($int));
$a = "string”; $a['index']; Now raises a warning
// protected $a; ++$this->a Now raises a warning
Progress
What now?
Finish Migrating Live
See if the hard toreproduce failures havestopped
Start using newfeatures!
Keep up to date
You should upgrade too!
Fin.
Questions?
@glenathan https://joind.in/9473