ãã®èšäºã¯ãã©ã€ããã¶ã€ã³ Advent Calendar 2021ã®4æ¥ç®ã®èšäºã§ãð
æšæ¥ã¯ïŒ Nyokki 倧å
çã®MySQLã®EXPLAIN ANALYZEã®èªã¿æ¹ãå匷ããã ãšããèšäºã§ããïŒ
çããèªã¿ãŸããããïŒïŒ
ãªãã§ãåããã©ã€ããã¶ã€ã³ã®ã¢ããã³ãã«ã¬ã³ããŒåå ããŠãããïŒïŒã£ãŠæããããããŸããã
ãšã³ããªãŒã¯èªç±ã§ãã瀟å å€ã®äººãã¡ãšçãäžããŠããããã§ãã
ã£ãŠæžããŠãã£ããã@hirodragon112ãã¡ã³ãªã®ã§åå ããŸããïœ
ããŠãäœãæžãããè¿·ã£ãŠããŸãããããã©ã€ããã¶ã€ã³ãšããã°PHPã£ãŠã€ã¡ãŒãžã匷ãã®ã§PHPãã¿ãšããããšã§Xdebugã®ããšãæžãããšæããŸãã
æè¿ã®è¥ããšã³ãžãã¢ã¯Xdebug䜿ããªãããç¥ããªããããã®ã§Xdebugã®çŽ¹ä»ãç°¡åã«æžããŠã¿ãŸãã
(ãããããŠPsySHãããããããªã«éèŠãªããªã£ãŠãããããŠããïŒïŒ
Xdebug is äœïŒ
å ¬åŒãµã€ãã«ãããš
Xdebug is an extension for PHP, and provides a range of features to improve the PHP development experience.
ã€ãŸããdebugã¯ãPHPã®æ¡åŒµæ©èœã§ãPHPã®éçºç°å¢ãæ¹åããããã®æ§ã
ãªæ©èœãæäŸããŸããããšã®ããšã§ãã
(ããããšãDeepL)
æ§ã ãªæ©èœãšããã®ã¯äž»ã«ä»¥äžã®5ã€ã«ãªããŸãã
- Step Debugging
- Improvements to PHP's error reporting
- Tracing
- Profiling
- Code Coverage Analysis
äžã€äžã€å 容ã確èªããŠãããŸãããã
Step Debugging
ã¡ã€ã³ã®æ©èœèšã£ãŠãéèšã§ã¯ãªããã¹ãããå®è¡ã§ãã
ãã¬ãŒã¯ãã€ã³ããšåŒã°ãããã®ãã³ãŒãã®è¡ã«èšå®ãããšãã®è¡ã§ããã°ã©ã ã®å®è¡ãæ¢ãŸããå€æ°ã®ç¶æ
ã確èªããããšãã§ããæ©èœã§ãã
Improvements to PHP's error reporting
var_dumpããªããã«ãªã£ããããšã©ãŒæã«ã¹ã¿ãã¯ãã¬ãŒã¹è¡šç€ºããŠãããããšã©ãŒãããããããããŠãããæ©èœã§ããã
æè¿ã ãšãã¬ãŒã ã¯ãŒã¯åŽã§ãããã°ããŒã«ããããªã£ãŠããŠããã®ã§è¥å¹²æ©æµãåãã¥ãããªã£ãŠããæ°ãããŸãã...ã
Tracing
åŒæ°ãšåŒã³åºãå Žæã䜿çšããŠããã¹ãŠã®é¢æ°åŒã³åºãããã£ã¹ã¯ã«æžã蟌ã¿ãŸãããªãã·ã§ã³ã§ãåé¢æ°ã®ãã¹ãŠã®å€æ°å²ãåœãŠãšæ»ãå€ãå«ãŸããŸãã
ã©ã®ããã«é¢æ°ã³ãŒã«ãããŠãããã調æ»ãããšãã«äŸ¿å©ã§ããã
(ã¶ã£ã¡ãã䜿ã£ãããšç¡ãã§ã...)
Profiling
èŠèŠåããŒã«ã䜿çšããŠãPHPã¢ããªã±ãŒã·ã§ã³ã®ããã©ãŒãã³ã¹ãåæããããã«ããã¯ãèŠã€ããããšãã§ããŸãã
Webgrindãšçµã¿åãããŠäœ¿ãã®ãäžè¬çãªã®ããªïŒ
æã¯xhprofãšã䜿ã£ãŠããã©ãä»ã ãšXdebugã§è¯ããããªæ°ãããŠããŸãã
Code Coverage Analysis
PHPUnitã§åäœãã¹ããå®è¡ãããšãã«ã³ãŒãããŒã¹ã®ã©ã®éšåãå®è¡ããããã瀺ãæ©èœã
ããå°å³ã«äŸ¿å©ã§ããã¹ãæŒããšãå¯èŠåãããã®ã§çµæ§å¥œããªæ©èœäžã€ã§ãã
Xdebugã®Step Debuggingã®è¯ããšããã»æªããšãã
ããŠãXdebugã®æ©èœããã£ãšèª¬æããŸãããããªãå¹
åºãæ©èœã沢山ãããŸããã
Xdebugå
¥ãããšé
ããšããã人ãããã£ããããŸããããŸãã¡ãã£ãšé
ããŠãå
ç¢ãªããã®ã»ããããã®ã§ã¯ã£ãŠæã£ãŠããŸãèªåã§ãã
å
šéšã®æ©èœã现ãã説æããŠãããšããªãã®éã«ãªã£ãŠããŸãã®ã§ãä»åã¯Step Debugging(ã¹ãããå®è¡)ã®ããšã«ã€ããŠã€ãã€ãæžããŠãããŸãã
è¯ããšãã
Xdebugã®äžçªéèŠãªæ©èœãšèšã£ãŠãéèšã§ã¯ãªãStep Debuggingã
ãã¬ãŒã¯ãã€ã³ããšåŒã°ããããœãŒã¹ã³ãŒãäžã®åŠçãäžæåæ¢ãããç®æã«ããŒã¯ãããå®è¡æã«ãã¬ãŒã¯ãã€ã³ãã®ç®æã§åŠçãæ¢ããŠå€æ°ã®äžèº«ã確èªãããããæ©èœã§ãã
ïŒèµ€ãæ ã®å³åŽã®èµ€ãäžžããã¬ãŒã¯ãã€ã³ãïŒ
ã©ããã§ãšã©ãŒãçºçããŠãããã©ãããããããªãå Žåããã©ãã§ãã®ã¡ãœããåŒã°ããŠããã ïŒïŒïŒã¿ãããªç¶æ³ã«éåžžã«æå¹ã§ãã
ããšã¯ãwebãã¬ãŒã ã¯ãŒã¯ãç解ãããšãã«ã倧掻èºããŸãã
ç§ã¯Xdebugããã£ããããããSymfonyãžã®ç解ãæ·±ããããšãã§ããŸããã
å人çã«è¯ããšæãçç±ã¯ä»¥äžã®äºç¹ã
- Variablesã§å®è¡æã®å€æ°ã確èªããããšãã§ãã
- Framesã§å®è¡é åºã確èªã§ãã
Variablesã§å®è¡æã®å€æ°ã確èªããããšãã§ãã
å®è¡æã«åŠçããšããŠãå€æ°ã®äžèº«ã確èªããããšãåºæ¥ãŸãã
var_dumpãLaravelã®ddã§ååãããããŸããããèŠãããããèŠããå€æ°ã®ç¯å²ãèãããšãã¡ãã®ã»ããé¥ãã«ããããšæããŸãã
Framesã§å®è¡é åºã確èªã§ãã
Frameså®è¡æã®ã¹ã¿ãã¯ãç¥ãäºãã§ããŸãã
ãã®å Žåã ãšindex.phpããå§ãŸã£ãŠProfileControllerã®38è¡ç®ãå®è¡ãããŠããããšãã²ãšç®ã§åããããšæããŸãã
ãŸããåã¹ã¿ãã¯ãã¯ãªãã¯ããããšã§VariablesåŽã«å€æ°ã衚瀺ããŠãããŸãã
ãããã£ãåŽé¢ãããã®ã§ãã¬ãŒã ã¯ãŒã¯ã®ãœãŒã¹ã³ãŒãã¯ãã¡ããã¡ãè¿œããããã§ãã
ãšãã«Symfonyã¿ããã«æœè±¡åºŠã®é«ããã¬ãŒã ã¯ãŒã¯ã ãšãã¡ããã¡ãç解ã«åœ¹ç«ã¡ãŸãããå®éã®ãããžã§ã¯ãã§ããœãŒã¹ã³ãŒãã®ææ¡ã«ããã圹ç«ã¡ãŸãã
æªããšãã
- èšå®ãé£ããã(ã©ããåå ã§ããŸãåããªãã®ãåå ã®ç¹å®ãé£ãã)
- ãã©ã¡ãŒã¿ã®é ç®ããããããªããïŒãšãã«Xdebug3ã«ãªã£ãŠå€ãã£ãŠããŸã£ãïŒ
- ããŒã«ã«ãªéçºç°å¢ããªããXdebugå°å ¥ãé£ãã(ãããã)
ãšãã£ããšããã§ããããïŒ
æ£çŽãªè©±nåèšå®ããããšã§èŠããã®ã§ããã¯é 匵ããããªãã®ããªãšæã£ãããããŸãã
Docker+PHPStormãªç°å¢ã§Xdebugã®èšå®ããã
äžçªéèŠãªãã€ã³ãã§ããã倧äºãªå
容ã¯èªåã®ããã°ã«ã¡ãã£ãšåã«æžããŠããŸãã
Dockerç°å¢ã§php8 + Xdebug3ãèšå®ãã
ã³ãã©ãåèã«ããŠããã ããã°ãšæããŸãðââïž
æåŸã«
å人çã«ã¯ãã£ãšã¿ããªãæ°è»œã«xdebugã䜿ã£ãã¹ãããå®è¡ãããæªæ¥ã«ãªãã°ãããªãš10幎ãããæãç¶ããŠããŸãã
ãªã«ãå°ã£ãããšãããã°@polidog ã«ã¡ã³ã·ã§ã³ãããã°ããçšåºŠã¯ãã«ãããããšæããŸãã
è¯ãã£ãæ°è»œã«ãªãã©ã€ãã ãããŒïŒ
ææ¥ã¯@tkek321ããã®AWSã«é¢ããèšäºã§ãïŒã楜ãã¿ã«ïŒïŒïŒ