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

NewRelicと戦うレガシーPHP

271fad8d53cd1f12f2b4b6d38e3d7bd3?s=47 uzulla
March 16, 2022

 NewRelicと戦うレガシーPHP

意識低いテクです
at: NRUG (New Relic User Group) Vol.2
when: 2022/03/16
by: @uzulla

271fad8d53cd1f12f2b4b6d38e3d7bd3?s=128

uzulla

March 16, 2022
Tweet

More Decks by uzulla

Other Decks in Programming

Transcript

  1. NewRelicͱઓ͏ ϨΨγʔPHP at: NRUG (New Relic User Group) Vol.2 when:

    2022/03/16 by: @uzulla
  2. ࣗݾ঺հ • uzulla • ϑϦʔͷPHPΤϯδχΞ • N+1ࣾͷMՕॴͷݱ৔ͰՔಇத • ྫ PR

    TIMES ͞Μ
  3. ஫:͜ͷτʔΫ͸ಛఆͷاۀʹ͍ͭͯޠ͍ͬͯ·ͤΜ • ࢲ͸ݱࡏਐߦͰɺNࣾ x Mݱ৔ͰՔಇத • աڈͷݱ৔਺͸֮͑ͯ͢Βډͳ͍ • ͨͩ͠ɺ৭ʑͳݱ৔Ͱࣅ͍ͯΔ͜ͱ͸͋Δ

  4. ࣗࣾ঺հͱ͔ͳ͍ΜͰએ఻ • PHPerKaigi 2022 • PHPͳํ͸ͥͻ • PR TIMESͷਓؒ΋ొஃ͠·͢

  5. NewRelic ❤ PHP • ϙϯͱ(ϛυϧ΢ΣΞతʹ)͍ΕΔ͚ͩͰಈ͘ • ύοʂͱ֎ͤΔ • ຊ൪ʹೖΕ͓͚ͯΔ΄ͲੑೳྼԽ௿͍ •

    Τϥʔɾྫ֎͕͍͍ײ͡ʹϦΞϧλΠϜूܭ • = ࠷ߴʂ
  6. ࢲͱNewRelic • ׂͱੲ͔Βɺ͔ͭͣ཭ΕͣϢʔβʔ • ʮ͓٬༷͕͍Εͯ͘ΕΔ͔ʯ࣍ୈ • ʢ·͋ɺ͝༧ࢉ͸͋ΔΑͶ…Θ͔Δ…ʣ • ͨͱ͑͹PR TIMES͞Μ͸ೖΕͯ͘ΕͯΔ

    • ʮ࢖͑ͯϥοΩʔʂʂʯ
  7. ࣗෲ()ͱͷ૬ੑͷΑ͞ • ༧ࢉ͸ग़ͳ͍͕ɺ΍ͬͯ΋͍͍ͱ͍͏ݱ৔΋͋Δ • ͢Δͱɺ֎͠΍͍͢͜ͱ΋ॏཁͰ͢ΑͶ… • PHP + NewRelic͸֎͠΍͍͢ʂ •

    (ίʔυʹೖΕͳͯ͘ྑ͍ͷͰ) • ISUCONͱ͔Ͱ΋ɺඵͰ֎ͤΔͷͰ࢖͑Δ
  8. ͯ͞ɺϨΨγʔPHP • ݹ͍ίʔυϕʔεͷPHP • PHP<=7…PHP<=5… • ࠷ۙ͸PHP8ະຬΛ੾Δ࣌୅͕ͩʢྫ: Laravel9ʣ NewRelic͸ͪΌΜͱಈ͘ʢخʣ

  9. ϨΨγʔPHPͱઓ͏೰Έ • ੵΈॏͳͬͨෛ࠴ίʔυ • error_reporting, display_errors=offͰݱ࣮ಀආ • ΤϥʔϩάΛݟͯͳ͍ʢ݁ߏଟ͘ͷݱ৔ʣ • ͱ͍͏͔ɺϩά͕ࣺͯΒΕ͍ͯΔ

    • ͋;ΕΔNotice, WarningΤϥʔ
  10. NewRelicͳΒʂ • ΤϥʔϩάΛಠࣗʹरͬͯूܭͯ͘͠ΕΔʂ • ͳʹ΋͠ͳͯ͘΋ࣗಈతʹϝτϦοΫʹ • ελοΫτϨʔε෇͖ʂ • ಉ͡ΤϥʔΛ෼ྨʂ •

    Error Inbox͔Βरͬͯ௚͚ͩ͢Ͱվળ͞ΕΔ • ෳ਺୆Ͱtail -f͠ͳ͍͍ͯ͘ͷ͸ָʂ()
  11. NewRelicΛ࢖Θͳ͍৔߹… • ϩάج൫…fluentd…kibana… • ूܭɾϝτϦΫε… • ϩʔςʔγϣϯ…DiskFull… • ෛՙ… •

    ༨෼ͳαʔόʔӡ༻… • etc,etc... େมͩͶ…
  12. ͯ͞ຊ୊ • ʮϦϑΝΫλϦϯά͍ͨ͠ʂʯ • ͦͼཱ͑ͭϨΨγʔ • ʮσουίʔυΛ҆શʹফ͍ͨ͠ʯ • ʮͰ΋ɺຊ౰ʹࢮΜͰΔͷ͔ͳ…ʯ

  13. ʮͦΕɺNRͰ؆୯ʹऩूͰ͖ΔΑʂʯ

  14. E_USER_WARNING(౳)Λ࢖͏ trigger_error( "This code is NOT DEAD", E_USER_WARNING ); •

    https://www.php.net/manual/ja/function.trigger-error.php • ϢʔβʔϨϕϧͷΤϥʔ/ܯࠂ/௨஌ϝοηʔδΛੜ੒͢Δ
  15. None
  16. None
  17. Error InboxʹΨϯΨϯ͸͍ͬͯ͘Δ • (΋ͪΖΜϑΟϧλ΋Ͱ͖Δ)

  18. ิ଍ɿE_USER_*ͱ͸ʁ • PHPʹ͸ྫ֎ʹࣅͨ(?) ผͷΤϥʔػߏ͕͋Δ • DB઀ଓࣦഊE_WARNINGͱ͔ɺΑ͘Έ·͢ΑͶʢന໨ʣ • E_USER_* ͸ɺϢʔβʔ͕ൃߦͰ͖ΔΤϥʔܕ •

    DEPRECATED, NOTICE, WARNING, ERROR,ͷ4छ • WARN·Ͱ͸࣮ߦ͕ࢭ·Βͳ͍ (͜ͱ͕׆༻ͷϛι̍) • display_errors=offͰӅͤΔ (͜ͱ͕׆༻ͷϛι̎)
  19. ո͍͠ॴʹೖΕ·͘Δ͚ͩ • ௿ෛՙͰ • ར༻৔ॴ͕Θ͔Δ • ूܭ΋ࣗಈతʹ͞ΕΔ • ຊ౰ʹফ͔ͤͨ΋λΠϜϥΠϯͰΘ͔Δ •

    શ෦͕Θ͔Δɻͦ͏ɺNewRelicͳΒͶ
  20. ͞Βʹݴ͑͹ • ༷ʑͳཧ༝ͰσϓϩΠͰ͖ͳ͍৔߹Ͱ΋… • ී௨ͷPHPͳΒɺຊ൪ʹsshͯ͠ɺ ௚઀viͯ͠ίʔυΛͿͬࢗ͢·ͰͰ͖Δ ʢίϨͰ΍ͬͯΔΘ͚Ͱ͸ͳ͍Ͱ͢ʂʂʣ

  21. ΋ͬͱ΋ͬͱ׆༻!!!!! • ༷ʑͳ৚݅Ͱಈతʹൃߦ΋Ͱ͖Δɻ ͨͱ͑͹ifͰʮ͋Γ͑ͳ͍஋ݕ஌ʯൃՐ΋Ͱ͖Δ if(!in_array($type, $allow_type_list)){ trigger_error("OOB!!", E_USER_WARNING); }

  22. • REQUEST_URIΛਖ਼نදݱͰҾֻ͚ͬΔͱ͔΋Α͍ if(preg_match( "|\A/v0.1/old_api/|u", $_SERVER['REQUEST_URI'] ){ trigger_error("deprecated...",E_USER_WARNING); }

  23. • ʮഇࢭ͞Εͨύϥϝλ͕͋Δʯͱ͔΋ʁ • php.iniͷauto_prepend_fileΛ׆༻͢Δͱָ͔΋ if(isset($_GET['session_id'])){ trigger_error("OMG!!",E_USER_WARNING); }

  24. ເ͕޿͕Δʂʂ • (ී௨ͷߦҝͰ͸ͳ͍Ͱ͢Ͷɺ͸͍)

  25. ޙย෇͚ • શจݕࡧͰফͤ͹OK • (E_USER_WARNINGͱ͔ී௨͔ͭΘͳ͍ͷͰ…) • Ծʹ࢒͍ͬͯͯ΋Τϥʔϩάʹग़Δ͔Β୳ͤΔ͠ɺ ௒ѱӨڹ͸ͳ͍

  26. ͱ͍͏͜ͱͰ(?)PHPʹNewRelic͸࠷ߴʂ • ݹ͍PHPݱ৔ͦ͜ɺඞܞ • ͱʹ͔͘ೖΕͯɺͲΜͲΜίʔυվળ • ύϑΥʔϚϯενϡʔχϯά͚ͩͰͳ͍ʂ • (໪࿦ɺࣗಈతʹ࣮ߦαϯϓϧͯ͠վળ΋) •

    Error Inbox ͚ͩͰ΋ศརʂ
  27. Ҏ্ʂ

  28. ҟৗͳཁ๬ • ϨϯαόΈ͍ͨͳͷͰ΋͏͍ͯ͝΄͍͠ͳ • ʢREST APIΛ͖ͨͨ·͘Ε͹Ͱ͖Δ…ʁʣ • ʮdl("newrelic.so")Ͱ͏͍ͨ͝Γ͠ͳ͍͔ͳ…ʯ • ʢҟৗͳཁ๬ͩͱཧղ͸͍ͯ͠·͢ʣ

    • ʮPHPʹৄ͍͠ʯNRͷਓ ͱ࿩ͯ͠Έ͍ͨ͆
  29. ΏΔ͍ئ๬ • (ʮ͘͝Ұൠతͳ͓٬༷ʯʹ͓͍ͯ…ʣ • ʮͰɺ͜Ε͍͘Β͔͔Δͷʁʯ • Ͱɺ༧ࢉ͕૊ΊͣɺೖΕΒΕͳ͍͜ͱ͕ଟ͍… • ʢࢼࢉ͕೉͍͠ʣ •

    !
  30. I ❤ NewRelic • NRͱPHPΛτϦοΩʔʹ࢖ͬͯΔਓͱ஌Γ߹͍͍ͨ • ࠷ޙʹɺPHPͳਓ͸PHPerKaigiʹ͝ࢀՃݕ౼͍ͩ͘͞