Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
NewRelicと戦うレガシーPHP
Search
uzulla
March 16, 2022
Programming
0
920
NewRelicと戦うレガシーPHP
意識低いテクです
at: NRUG (New Relic User Group) Vol.2
when: 2022/03/16
by: @uzulla
uzulla
March 16, 2022
Tweet
Share
More Decks by uzulla
See All by uzulla
似たもの同士のPerlとPHP
uzulla
1
150
More Context, Better Code. 既存コードやOAS等をコンテキストとしてLLMに与える事で、よりよいコード生成を行う話
uzulla
1
120
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
200
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
140
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
2.1k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
4
1k
PHPerが ISUCONでやるべき事
uzulla
1
1.1k
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
260
test is not a job
uzulla
1
510
Other Decks in Programming
See All in Programming
ErdMap: Thinking about a map for Rails applications
makicamel
1
830
Terraform で作る Amazon ECS の CI/CD パイプライン
hiyanger
0
110
Scaling your build logic
antalmonori
1
120
DMMオンラインサロンアプリのSwift化
hayatan
0
220
Flatt Security XSS Challenge 解答・解説
flatt_security
0
780
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
140
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
970
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
ゼロからの、レトロゲームエンジンの作り方
tokujiros
3
1.1k
Linux && Docker 研修/Linux && Docker training
forrep
8
1.3k
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
400
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
8
970
Featured
See All Featured
Designing Experiences People Love
moore
139
23k
Automating Front-end Workflow
addyosmani
1366
200k
GraphQLとの向き合い方2022年版
quramy
44
13k
Thoughts on Productivity
jonyablonski
68
4.4k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Faster Mobile Websites
deanohume
305
30k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Building Your Own Lightsaber
phodgson
104
6.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
3k
4 Signs Your Business is Dying
shpigford
182
22k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
Transcript
NewRelicͱઓ͏ ϨΨγʔPHP at: NRUG (New Relic User Group) Vol.2 when:
2022/03/16 by: @uzulla
ࣗݾհ • uzulla • ϑϦʔͷPHPΤϯδχΞ • N+1ࣾͷMՕॴͷݱͰՔಇத • ྫ PR
TIMES ͞Μ
:͜ͷτʔΫಛఆͷاۀʹ͍ͭͯޠ͍ͬͯ·ͤΜ • ࢲݱࡏਐߦͰɺNࣾ x MݱͰՔಇத • աڈͷݱ֮͑ͯ͢Βډͳ͍ • ͨͩ͠ɺ৭ʑͳݱͰࣅ͍ͯΔ͜ͱ͋Δ
ࣗࣾհͱ͔ͳ͍ΜͰએ • PHPerKaigi 2022 • PHPͳํͥͻ • PR TIMESͷਓؒొஃ͠·͢
NewRelic ❤ PHP • ϙϯͱ(ϛυϧΣΞతʹ)͍ΕΔ͚ͩͰಈ͘ • ύοʂͱ֎ͤΔ • ຊ൪ʹೖΕ͓͚ͯΔ΄ͲੑೳྼԽ͍ •
Τϥʔɾྫ֎͕͍͍ײ͡ʹϦΞϧλΠϜूܭ • = ࠷ߴʂ
ࢲͱNewRelic • ׂͱੲ͔Βɺ͔ͭͣΕͣϢʔβʔ • ʮ͓٬༷͕͍Εͯ͘ΕΔ͔ʯ࣍ୈ • ʢ·͋ɺ͝༧ࢉ͋ΔΑͶ…Θ͔Δ…ʣ • ͨͱ͑PR TIMES͞ΜೖΕͯ͘ΕͯΔ
• ʮ͑ͯϥοΩʔʂʂʯ
ࣗෲ()ͱͷ૬ੑͷΑ͞ • ༧ࢉग़ͳ͍͕ɺ͍͍ͬͯͱ͍͏ݱ͋Δ • ͢Δͱɺ֎͍͢͜͠ͱॏཁͰ͢ΑͶ… • PHP + NewRelic֎͍͢͠ʂ •
(ίʔυʹೖΕͳͯ͘ྑ͍ͷͰ) • ISUCONͱ͔ͰɺඵͰ֎ͤΔͷͰ͑Δ
ͯ͞ɺϨΨγʔPHP • ݹ͍ίʔυϕʔεͷPHP • PHP<=7…PHP<=5… • ࠷ۙPHP8ະຬΛΔ͕࣌ͩʢྫ: Laravel9ʣ NewRelicͪΌΜͱಈ͘ʢخʣ
ϨΨγʔPHPͱઓ͏Έ • ੵΈॏͳͬͨෛ࠴ίʔυ • error_reporting, display_errors=offͰݱ࣮ಀආ • ΤϥʔϩάΛݟͯͳ͍ʢ݁ߏଟ͘ͷݱʣ • ͱ͍͏͔ɺϩά͕ࣺͯΒΕ͍ͯΔ
• ͋;ΕΔNotice, WarningΤϥʔ
NewRelicͳΒʂ • ΤϥʔϩάΛಠࣗʹरͬͯूܭͯ͘͠ΕΔʂ • ͳʹ͠ͳͯࣗ͘ಈతʹϝτϦοΫʹ • ελοΫτϨʔε͖ʂ • ಉ͡ΤϥʔΛྨʂ •
Error Inbox͔Βर͚ͬͯͩ͢Ͱվળ͞ΕΔ • ෳͰtail -f͠ͳ͍͍ͯ͘ͷָʂ()
NewRelicΛΘͳ͍߹… • ϩάج൫…fluentd…kibana… • ूܭɾϝτϦΫε… • ϩʔςʔγϣϯ…DiskFull… • ෛՙ… •
༨ͳαʔόʔӡ༻… • etc,etc... େมͩͶ…
ͯ͞ຊ • ʮϦϑΝΫλϦϯά͍ͨ͠ʂʯ • ͦͼཱ͑ͭϨΨγʔ • ʮσουίʔυΛ҆શʹফ͍ͨ͠ʯ • ʮͰɺຊʹࢮΜͰΔͷ͔ͳ…ʯ
ʮͦΕɺNRͰ؆୯ʹऩूͰ͖ΔΑʂʯ
E_USER_WARNING()Λ͏ trigger_error( "This code is NOT DEAD", E_USER_WARNING ); •
https://www.php.net/manual/ja/function.trigger-error.php • ϢʔβʔϨϕϧͷΤϥʔ/ܯࠂ/௨ϝοηʔδΛੜ͢Δ
None
None
Error InboxʹΨϯΨϯ͍ͬͯ͘Δ • (ͪΖΜϑΟϧλͰ͖Δ)
ิɿE_USER_*ͱʁ • PHPʹྫ֎ʹࣅͨ(?) ผͷΤϥʔػߏ͕͋Δ • DBଓࣦഊE_WARNINGͱ͔ɺΑ͘Έ·͢ΑͶʢനʣ • E_USER_* ɺϢʔβʔ͕ൃߦͰ͖ΔΤϥʔܕ •
DEPRECATED, NOTICE, WARNING, ERROR,ͷ4छ • WARN·Ͱ࣮ߦ͕ࢭ·Βͳ͍ (͜ͱ͕׆༻ͷϛι̍) • display_errors=offͰӅͤΔ (͜ͱ͕׆༻ͷϛι̎)
ո͍͠ॴʹೖΕ·͘Δ͚ͩ • ෛՙͰ • ར༻ॴ͕Θ͔Δ • ूܭࣗಈతʹ͞ΕΔ • ຊʹফ͔ͤͨλΠϜϥΠϯͰΘ͔Δ •
શ෦͕Θ͔Δɻͦ͏ɺNewRelicͳΒͶ
͞Βʹݴ͑ • ༷ʑͳཧ༝ͰσϓϩΠͰ͖ͳ͍߹Ͱ… • ී௨ͷPHPͳΒɺຊ൪ʹsshͯ͠ɺ viͯ͠ίʔυΛͿͬ͢·ͰͰ͖Δ ʢίϨͰͬͯΔΘ͚Ͱͳ͍Ͱ͢ʂʂʣ
ͬͱͬͱ׆༻!!!!! • ༷ʑͳ݅ͰಈతʹൃߦͰ͖Δɻ ͨͱ͑ifͰʮ͋Γ͑ͳ͍ݕʯൃՐͰ͖Δ if(!in_array($type, $allow_type_list)){ trigger_error("OOB!!", E_USER_WARNING); }
• REQUEST_URIΛਖ਼نදݱͰҾֻ͚ͬΔͱ͔Α͍ if(preg_match( "|\A/v0.1/old_api/|u", $_SERVER['REQUEST_URI'] ){ trigger_error("deprecated...",E_USER_WARNING); }
• ʮഇࢭ͞Εͨύϥϝλ͕͋Δʯͱ͔ʁ • php.iniͷauto_prepend_fileΛ׆༻͢Δͱָ͔ if(isset($_GET['session_id'])){ trigger_error("OMG!!",E_USER_WARNING); }
ເ͕͕Δʂʂ • (ී௨ͷߦҝͰͳ͍Ͱ͢Ͷɺ͍)
ޙย͚ • શจݕࡧͰফͤOK • (E_USER_WARNINGͱ͔ී௨͔ͭΘͳ͍ͷͰ…) • Ծʹ͍ͬͯͯΤϥʔϩάʹग़Δ͔Β୳ͤΔ͠ɺ ѱӨڹͳ͍
ͱ͍͏͜ͱͰ(?)PHPʹNewRelic࠷ߴʂ • ݹ͍PHPݱͦ͜ɺඞܞ • ͱʹ͔͘ೖΕͯɺͲΜͲΜίʔυվળ • ύϑΥʔϚϯενϡʔχϯά͚ͩͰͳ͍ʂ • (ɺࣗಈతʹ࣮ߦαϯϓϧͯ͠վળ) •
Error Inbox ͚ͩͰศརʂ
Ҏ্ʂ
ҟৗͳཁ • ϨϯαόΈ͍ͨͳͷͰ͏͍ͯ͝΄͍͠ͳ • ʢREST APIΛ͖ͨͨ·͘ΕͰ͖Δ…ʁʣ • ʮdl("newrelic.so")Ͱ͏͍ͨ͝Γ͠ͳ͍͔ͳ…ʯ • ʢҟৗͳཁͩͱཧղ͍ͯ͠·͢ʣ
• ʮPHPʹৄ͍͠ʯNRͷਓ ͱͯ͠Έ͍ͨ͆
ΏΔ͍ئ • (ʮ͘͝Ұൠతͳ͓٬༷ʯʹ͓͍ͯ…ʣ • ʮͰɺ͜Ε͍͘Β͔͔Δͷʁʯ • Ͱɺ༧ࢉ͕ΊͣɺೖΕΒΕͳ͍͜ͱ͕ଟ͍… • ʢࢼࢉ͕͍͠ʣ •
!
I ❤ NewRelic • NRͱPHPΛτϦοΩʔʹͬͯΔਓͱΓ߹͍͍ͨ • ࠷ޙʹɺPHPͳਓPHPerKaigiʹ͝ࢀՃݕ౼͍ͩ͘͞