Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Glen Mailer

October 05, 2013
Tweet

More Decks by Glen Mailer

Other Decks in Programming

Transcript

  1. View Slide

  2. Glen Mailer

    View Slide

  3. The Codebase

    View Slide

  4. First commit April 2010

    60k commits since

    View Slide

  5. 9300 PHP files

    690k lines of code
    According to git and cloc

    View Slide

  6. 10 releases a week

    35 active committers

    10 concurrent streams

    1 deployable

    View Slide

  7. The Platform

    View Slide

  8. 8 Test Environments

    1 Staging Environment

    2 Live Environments

    View Slide

  9. 74 Live PHP boxes

    View Slide

  10. 1300 req/s peak

    500k uniques/week

    View Slide

  11. Why?

    View Slide

  12. Using basically the same
    PHP version as the first
    commit
    with security patches

    View Slide

  13. PHP 5.3 is dead

    View Slide

  14. Bug fixes

    Performance

    View Slide

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

    View Slide

  16. but no smoking gun

    View Slide

  17. Bug #64827

    GC causes segfaults

    View Slide

  18. The Plan

    View Slide

  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

    View Slide

  20. Vagrant

    Chef

    Unit Tests

    Acceptance Tests

    View Slide

  21. Hack hack hack...

    View Slide

  22. 3 days later

    View Slide

  23. What changed?

    View Slide

  24. APC

    becomes

    OPcache and APCu

    View Slide

  25. Check for new function, fall back to old one
    if (function_exists('opcache_reset')) {
    opcache_reset();
    } else {
    apc_clear_cache();
    }

    View Slide

  26. “The PHP api will retain
    compatibility with APC, as
    will common configuration
    options, providing a drop
    in replacement.”
    APCu

    View Slide

  27. Not a drop in replacement

    View Slide

  28. APCu 4.0.1

    APCu 4.0.2

    View Slide

  29. No more

    mysql_

    View Slide

  30. It will not be missed

    View Slide

  31. preg_replace /e

    becomes

    preg_replace_callback

    View Slide

  32. (string) array()

    Now raises a warning
    Still returns “Array”

    View Slide

  33. Type-checked function
    function inc($int) {
    if (!is_int($int)) {
    throw new InvalidArgumentException(
    'Expected int, got: ' . $int
    );
    }
    return $int + 1;
    }

    View Slide

  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()
    );
    }

    View Slide

  35. Simplest fix
    throw new InvalidArgumentException(
    'Expected int, got: ' .
    json_encode($int)
    );

    View Slide

  36. $a = "string”;

    $a['index'];

    Now raises a warning

    View Slide

  37. // protected $a;

    ++$this->a

    Now raises a warning

    View Slide

  38. Progress

    View Slide

  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

    View Slide

  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

    View Slide

  41. What now?

    View Slide

  42. Finish Migrating Live

    View Slide

  43. See if the hard to
    reproduce failures have
    stopped

    View Slide

  44. Start using new
    features!

    View Slide

  45. Keep up to date

    View Slide

  46. You should upgrade too!

    View Slide

  47. Fin.

    View Slide

  48. Questions?

    View Slide

  49. @glenathan

    https://joind.in/9473

    View Slide