Slide 1

Slide 1 text

1 Hitting the Turbo Button: Upgrading to PHP 7 at Etsy @wcgallego

Slide 2

Slide 2 text

2 Hey, I’m Will! Ops Engineer @ Etsy @wcgallego

Slide 3

Slide 3 text

3 @wcgallego

Slide 4

Slide 4 text

4 Roadmap •Brief history of PHP 5 point release upgrades at Etsy •Our use of HHVM •Deciding between Hack/HHVM vs. PHP 7 •Deployment of PHP 7 •Wins, pitfalls, and features in PHP 7 @wcgallego

Slide 5

Slide 5 text

5 #VUNPTUJNQPSUBOUMZ *XBOUZPVUPCFTVDDFTTGVMBU VQHSBEJOH1)1 @wcgallego

Slide 6

Slide 6 text

6 PHP @ Etsy Timeline @wcgallego Prehistory 2012 2013 2014 2015 … 2012 …to 5.3 PHP 5.2 2013 …to 5.4 2014 …to 5.5 2015 …5.6?

Slide 7

Slide 7 text

Reworking our API Architecture @wcgallego

Slide 8

Slide 8 text

8 @wcgallego Webs Browser DBs Previous Approach

Slide 9

Slide 9 text

9 @wcgallego Webs Browser Internal API (multicurl) API Node API Node API Node API First Approach DBs

Slide 10

Slide 10 text

10 @wcgallego Rising API Requests

Slide 11

Slide 11 text

HHVM to the rescue! @wcgallego

Slide 12

Slide 12 text

12 @wcgallego

Slide 13

Slide 13 text

13 @wcgallego

Slide 14

Slide 14 text

14 @wcgallego

Slide 15

Slide 15 text

15 PHP @ Etsy Timeline @wcgallego Spring
 2015 Summer
 2015 Fall
 2015 January
 2016 February
 2016 Summer
 2016 Early PHP 7 Testing/Benchmarks

Slide 16

Slide 16 text

16 https://wiki.php.net/rfc/php6 “Version 6 is generally associated with failure in the world of dynamic language” @wcgallego Wait…what happened to PHP 6?

Slide 17

Slide 17 text

17 PHP @ Etsy Timeline @wcgallego Spring
 2015 Summer
 2015 Fall
 2015 January
 2016 February
 2016 Summer
 2016 Porting Etsy Extensions to PHP 7

Slide 18

Slide 18 text

18 https://bugs.php.net/bug.php?id=72396 @wcgallego https://php-lxr.adamharvey.name/source/ http://lxr.php.net/

Slide 19

Slide 19 text

19 1)1WT)BDL))7.
 8IJDIEPXFDIPPTF @wcgallego

Slide 20

Slide 20 text

20 http://talks.php.net/velocity15#/wpbench http://hhvm.com/blog/9293/lockdown-results-and-hhvm-performance https://kinsta.com/blog/the-definitive-php-7-final-version-hhvm- benchmark/ @wcgallego

Slide 21

Slide 21 text

21 Hack/HHVM @wcgallego Cons •More experiential knowledge with
 PHP/mod_php than Hack/HHVM/ fastcgi •Debugging multithreaded extensions •Different environment than Facebook: multi-curl in API at Etsy vs. async at Facebook •HHVM deploy shorter, but Hack everywhere a multiyear project Pros •Async (cooperative multitasking) •Generics •Collections (Vectors, Maps, Sets, Pairs) •Tuples, Enums, Shapes •compile time features like void return

Slide 22

Slide 22 text

22 PHP 7 @wcgallego Cons •Need to write our own static analyzer •Core not yet prod ready •Extensions hadn’t seen wide internal testing like core •Some type features Hack has not in PHP Pros •All of our editors supported PHP 7 - vim, emacs, sublime text, phpstorm, etc. •Unsure direction Facebook takes Hack •Maintain current understanding of how our site runs •Shorter migration •Rasmus

Slide 23

Slide 23 text

23 PHP @ Etsy Timeline @wcgallego Spring
 2015 Summer
 2015 Fall
 2015 January
 2016 February
 2016 Summer
 2016 Decision to deploy PHP 7

Slide 24

Slide 24 text

24 4 2 1 3 Staging Fix Tests 100% Dev Compatible with PHP 5 and PHP 7 code, still running PHP 5 Test PHP 7 running in safe environment Prevent introduction of PHP 7 code to PHP 5 boxes PHP 7 Deployment Plan Production Slow introduction to pools, careful eye on perf and errors @wcgallego

Slide 25

Slide 25 text

25 PHPUnit
 Upgrade before you start! @wcgallego

Slide 26

Slide 26 text

26 PHPUnit Tests: 17815 Assertions: 61346 Errors: 66 Failures: 120 https://github.com/krakjoe/uopz @wcgallego

Slide 27

Slide 27 text

27 Phan https://github.com/etsy/phan @wcgallego

Slide 28

Slide 28 text

28 Tee-ing Requests @wcgallego

Slide 29

Slide 29 text

29 https://github.com/buger/gor @wcgallego

Slide 30

Slide 30 text

30 PHP @ Etsy Timeline @wcgallego Spring
 2015 Summer
 2015 Fall
 2015 January
 2016 February
 2016 Summer
 2016 Single web node running PHP 7

Slide 31

Slide 31 text

31 PHP @ Etsy Timeline @wcgallego Spring
 2015 Summer
 2015 Fall
 2015 January
 2016 February
 2016 Summer
 2016 PHP 7 deployed to all web nodes NPOUITTJODFCFHJOOJOHFYUFOTJPOTQPSUJOH NPOUITJOUFHSBUJOHJOUP&UTZ NPOUITBGUFSSFMFBTF

Slide 32

Slide 32 text

32 ))7.1)1 @wcgallego

Slide 33

Slide 33 text

33 Other Snowflakes @wcgallego

Slide 34

Slide 34 text

34 PHP @ Etsy Timeline @wcgallego Spring
 2015 Summer
 2015 Fall
 2015 January
 2016 February
 2016 Summer
 2016 Deployed to Dev VMs PHP 7 everywhere!

Slide 35

Slide 35 text

35 Perf wins! @wcgallego

Slide 36

Slide 36 text

.FNPSZXJOT 36 @wcgallego

Slide 37

Slide 37 text

4ZTUFN$16XJOT 37 @wcgallego

Slide 38

Slide 38 text

6TFS$16XJOT 38 @wcgallego

Slide 39

Slide 39 text

)PNFQBHFEFMJWFSZXJOT 39 @wcgallego

Slide 40

Slide 40 text

-JTUJOHEFMJWFSZXJOT 40 @wcgallego

Slide 41

Slide 41 text

'FXFSIPTUT 41 @wcgallego

Slide 42

Slide 42 text

42 $BVUJPO @wcgallego

Slide 43

Slide 43 text

$PEFQJUGBMMT6OJGPSN7BS1BSTJOH 43 @wcgallego $class->$foo['bar'](); In PHP 5 that is interpreted as: $class->($foo['bar'])() while in PHP 7 it is: ($class->$foo)['bar']() It is easy enough to fix by adding curlies: $class->{$foo[‘bar']}()

Slide 44

Slide 44 text

$PEFQJUGBMMT6OJGPSN7BS1BSTJOH 44 @wcgallego $class->$foo['bar'](); In PHP 5 that is interpreted as: $class->($foo['bar'])() while in PHP 7 it is: ($class->$foo)['bar']() It is easy enough to fix by adding curlies: $class->{$foo[‘bar']}()

Slide 45

Slide 45 text

$PEFQJUGBMMT6OJGPSN7BS1BSTJOH 45 @wcgallego $class->$foo['bar'](); In PHP 5 that is interpreted as: $class->($foo['bar'])() while in PHP 7 it is: ($class->$foo)['bar']() It is easy enough to fix by adding curlies: $class->{$foo[‘bar']}()

Slide 46

Slide 46 text

$PEFQJUGBMMT6OJGPSN7BS1BSTJOH 46 @wcgallego $class->$foo['bar'](); In PHP 5 that is interpreted as: $class->($foo['bar'])() while in PHP 7 it is: ($class->$foo)['bar']() It is easy enough to fix by adding curlies: $class->{$foo[‘bar']}()

Slide 47

Slide 47 text

$PEFQJUGBMMT"TTPDJBUJWF"SSBZ4PSUJOH 1, "b" => 1 ]; asort($foo); print_r($foo); 47 @wcgallego PHP 5: Array ( [b] => 1 [a] => 1 ) PHP 7: Array ( [a] => 1 [b] => 1 )

Slide 48

Slide 48 text

$PEFQJUGBMMT"TTPDJBUJWF"SSBZ4PSUJOH 1, "b" => 1 ]; asort($foo); print_r($foo); 48 @wcgallego PHP 5: Array ( [b] => 1 [a] => 1 ) PHP 7: Array ( [a] => 1 [b] => 1 )

Slide 49

Slide 49 text

$PEFQJUGBMMT"TTPDJBUJWF"SSBZ4PSUJOH 1, "b" => 1 ]; asort($foo); print_r($foo); 49 @wcgallego PHP 5: Array ( [b] => 1 [a] => 1 ) PHP 7: Array ( [a] => 1 [b] => 1 )

Slide 50

Slide 50 text

$PEFQJUGBMMT$BUDIBCMF&SSPST 50 @wcgallego

Slide 51

Slide 51 text

$PEFQJUGBMMT3FNPWFE%FQSFDBUFE'VODUJPOT 51 @wcgallego mysql_* -> mysqli_* For example:
 mysql_connect() should now be mysqli_connect() or used PDO class Legacy extension: https://github.com/php/pecl-database-mysql

Slide 52

Slide 52 text

52 0UIFSJODPNQBUJCMFDIBOHFT http://php.net/manual/en/migration70.incompatible.php http://php.net/manual/en/migration70.deprecated.php @wcgallego

Slide 53

Slide 53 text

53 &YUFOTJPOT @wcgallego • gearman • msgpack • oauth • memcached • gmagick •…a dozen more!

Slide 54

Slide 54 text

54 SOAP ’n Certs PHP 7 is stricter about cert comparisons @wcgallego

Slide 55

Slide 55 text

55 SOAP ’n Certs 1. Disable WSDL cache
 (http://lornajane.net/posts/2015/soapfault-when-switching-php-versions) 2. Update your certs! 3. use FQDN instead of IPs 4.* Could also turn off peer verification (but probably not advisable) @wcgallego

Slide 56

Slide 56 text

56 /6." @wcgallego

Slide 57

Slide 57 text

57 On NUMA @wcgallego

Slide 58

Slide 58 text

58 But enough of the doom and gloom... @wcgallego

Slide 59

Slide 59 text

/FXGFBUVSFTUPDIFDLPVU • Scalar Type Declarations • Return Type Declarations • NULL coalescing operator • phpdbg • spaceship operator • const arrays 59 @wcgallego

Slide 60

Slide 60 text

60 .PSFGFBUVSFT http://php.net/manual/en/migration70.new-features.php @wcgallego

Slide 61

Slide 61 text

'VUVSFUXFBLTBU&UTZ • File backed opcache - cli speed up, avoid thundering herd on graceful restarts • Better compilation! Latest GCC, ICC, etc. • FDO (Feedback Directed Optimization) as part of GCC > 5 • Tuning to avoid filling up opcache as often 61 @wcgallego

Slide 62

Slide 62 text

1BSUJOHUIPVHIUT • Plan first, be ready to be flexible • Static analyzers/Tests/Teeing are wonderful • Have a back up plan • Don’t be afraid to contribute back to PHP • Get ready for a huge bucket of win 62 @wcgallego

Slide 63

Slide 63 text

63 5IBOLT @wcgallego https://joind.in/talk/41de3

Slide 64

Slide 64 text

64 <>IUUQTXXXGMJDLSDPNQIPUPTECSFLLF <>JNBHFIUUQXXXCVTJOFTTJOTJEFSDPNJOTJEFFUTZTOFXQFSLGJMMFEPGGJDF <>IUUQTXXXGMJDLSDPNQIPUPTKBOJUPST <>IUUQTXXXGMJDLSDPNQIPUPT!/ <>IUUQTFOXJLJQFEJBPSHXJLJ1FSM <>IUUQTXXXGMJDLSDPNQIPUPTDPOCPO <>IUUQTXXXGMJDLSDPNQIPUPT!/ <>IUUQTXXXGMJDLSDPNQIPUPT!/ <>IUUQTXXXGMJDLSDPNQIPUPTFDPMJ @wcgallego