Upgrading from PHP 5.3 to 5.5

Upgrading from PHP 5.3 to 5.5

A small talk on the experiences gained from migrating from PHP 5.3 to 5.5.

02cd14759ba3327f68f737131947781f?s=128

Glen Mailer

October 05, 2013
Tweet

Transcript

  1. None
  2. Glen Mailer

  3. The Codebase

  4. First commit April 2010
 60k commits since

  5. 9300 PHP files
 690k lines of code According to git

    and cloc
  6. 10 releases a week
 35 active committers
 10 concurrent streams


    1 deployable
  7. The Platform

  8. 8 Test Environments
 1 Staging Environment
 2 Live Environments

  9. 74 Live PHP boxes

  10. 1300 req/s peak
 500k uniques/week

  11. Why?

  12. Using basically the same PHP version as the first commit

    with security patches
  13. PHP 5.3 is dead

  14. Bug fixes
 Performance

  15. New Features! short array syntax traits $this in closures yield

    finally
  16. but no smoking gun

  17. Bug #64827
 GC causes segfaults

  18. The Plan

  19. 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
  20. Vagrant
 Chef
 Unit Tests
 Acceptance Tests

  21. Hack hack hack...

  22. 3 days later

  23. What changed?

  24. APC
 becomes
 OPcache and APCu

  25. Check for new function, fall back to old one if

    (function_exists('opcache_reset')) { opcache_reset(); } else { apc_clear_cache(); }
  26. “The PHP api will retain compatibility with APC, as will

    common configuration options, providing a drop in replacement.” APCu
  27. Not a drop in replacement

  28. APCu 4.0.1
 APCu 4.0.2

  29. No more
 mysql_

  30. It will not be missed

  31. preg_replace /e
 becomes
 preg_replace_callback

  32. (string) array()
 Now raises a warning Still returns “Array”

  33. Type-checked function function inc($int) { if (!is_int($int)) { throw new

    InvalidArgumentException( 'Expected int, got: ' . $int ); } return $int + 1; }
  34. 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() ); }
  35. Simplest fix throw new InvalidArgumentException( 'Expected int, got: ' .

    json_encode($int) );
  36. $a = "string”;
 $a['index'];
 Now raises a warning

  37. // protected $a;
 ++$this->a
 Now raises a warning

  38. Progress

  39. 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
  40. 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
  41. What now?

  42. Finish Migrating Live

  43. See if the hard to reproduce failures have stopped

  44. Start using new features!

  45. Keep up to date

  46. You should upgrade too!

  47. Fin.

  48. Questions?

  49. @glenathan https://joind.in/9473