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
900
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
110
More Context, Better Code. 既存コードやOAS等をコンテキストとしてLLMに与える事で、よりよいコード生成を行う話
uzulla
1
110
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
170
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
120
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
2k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
4
920
PHPerが ISUCONでやるべき事
uzulla
1
1k
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
240
test is not a job
uzulla
1
500
Other Decks in Programming
See All in Programming
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
140
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
850
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
180
AWS認定資格を勉強した先に何があったか
satoshi256kbyte
2
190
Develop iOS apps with Neovim / vimconf_2024
uhooi
1
340
useSyncExternalStoreを使いまくる
ssssota
4
840
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
0
180
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1k
Thoughts and experiences on Rust and TypeScript
unvalley
2
220
WebAssembly Unleashed: Powering Server-Side Applications
chrisft25
0
2.1k
.NET 9アプリをCGIとして レンタルサーバーで動かす
mayuki
1
760
Recoilを剥がしている話
kirik
4
6k
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
The World Runs on Bad Software
bkeepers
PRO
65
11k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Six Lessons from altMBA
skipperchong
27
3.5k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
900
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
1
150
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
260
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ʹ͝ࢀՃݕ౼͍ͩ͘͞