ãšã³ããªãŒ
Habréã«ã¯ãWebéçºã®èå³æ·±ãè€éãªåŽé¢ã説æããèšäºãå€æ°ãããŸãããWebéçºè ãšããŠã®ãã£ãªã¢ã®åãã«ããPHPã§24æéãããæ·±å»ãªã¬ãã«ã§ã®éçºã§ããããã®åé¡ã«é¢ããç§ã®çµéšãå ±æããããšæããŸãã
Webã¢ããªã±ãŒã·ã§ã³ã®æ©èœã«ãããã¯ã©ã€ã¢ã³ããšãµãŒããŒã®2ã€ã®éšåã«åå²ãããŸãã ã¯ã©ã€ã¢ã³ãåŽã§ã¯ãJavaScriptã³ãŒããæ©èœããŠããŸãïŒVBScriptã¯ã©ããã§èŠã€ãããããããŸãããããããããã®å Žåã¯èæ ®ããŸããïŒããµãŒããŒåŽã§ã¯ãååãšããŠå€ãã®ãã®ããããŸããã Webã¢ããªã±ãŒã·ã§ã³ã®ãµãŒããŒåŽã ã¯ã©ã€ã¢ã³ãåŽã§ã®Flashã¢ããªã±ãŒã·ã§ã³ã®ãããã°ãšãããã¡ã€ãªã³ã°ã«ã€ããŠè©±ãããšãèå³æ·±ãã§ãããããåãäžããããŠãããããã¯ã¯ãã§ã«åºç¯å²ã«æž¡ã£ãŠããã®ã§ãä»ã®ãšããã¯æŸã£ãŠãããŸãããã
HTMLã³ãŒãã®åæãšæ€èšŒã¯ãã¯ã©ã€ã¢ã³ãã³ãŒãã®ãããã°ã¿ã¹ã¯ã«èµ·å ããå ŽåããããŸãã ããã¯ãããã°ã©ãã³ã°ã®åéã ãã§ãªãéèŠã§ãããããã§ãã
æ€èšãããåé¡ã®äžéšã¯ä»ã®èšäºã§ãã§ã«æ€èšãããŠãããããããžã®ãªã³ã¯ãæäŸããŸããã
ã¯ã©ã€ã¢ã³ãã³ãŒãã®ãããã°ãšãããã¡ã€ãªã³ã°
JavaScriptã³ãŒãããããã°ãããã¯ã©ã·ãã¯ããªæ¹æ³ã¯ã
alert
é¢æ°ãšãã®æŽŸçç©ã䜿çšããããšã§ãã ãã£ãªã¢ã®åãã«ãJavaScriptã®
print_r
é¢æ°ãå人çã«äœæããããšãèŠããŠããŸããé åãšãªããžã§ã¯ãã®ãããã°æ å ±ãåºåããæ©èœããªãã£ãããã§ãã 次ã®ããã«ãªããŸããã
function print_r(variable) { if (variable instanceof Array || variable instanceof Object) { var key; for (key in variable) alert(key + ' => ' + variable[key]); } else { alert(variable); } }
ãã¡ãããã¹ããŒãã®ãããã¡ã€ãªã³ã°ã¯ãŸã£ããè¡ãããŠããŸããã
ãã®ã¢ãããŒãã«ããã ã³ã³ãœãŒã«ãªããžã§ã¯ãã«é¢ããæ å ±ã§ããé©åœçã§ãã
Webã¢ããªã±ãŒã·ã§ã³ã®ã¯ã©ã€ã¢ã³ãåŽã®ä»æ§ã§ã¯ãäžè¬çãªãã¹ãŠã®ãã©ãŠã¶ãŒã§ã³ãŒãã®ãããã°ãå¿ èŠã§ãã ãã¡ãããInternet Explorerããã³ä»ã®
Mozilla Firefox
ãããããFirefoxã¯ã¯ã©ã€ã¢ã³ãã³ãŒãã®ãããã°ã®å é§è ãšèšããã§ãããã é·ãéãéçºã«æé©ãªãã©ãŠã¶ãšããŠç€ºãããŠããŸãããã Firebugæ¡åŒµæ©èœã®ãããã§ãHTMLã³ãŒãã®æ€èšŒãé€ãå¿ èŠãªæ©èœããã¹ãŠå«ãŸããŠããå¯èœæ§ããããŸãã
ãŸããããŒãžã§ã³4ãããçµã¿èŸŒã¿ã®Webã³ã³ãœãŒã«ãç»å ŽããŸãããããã¯ãFirebugã®[ã³ã³ãœãŒã«]ã¿ããš[ãããã¯ãŒã¯]ã¿ãã®æ©èœã®äžéšãããã³ããã€ãã®CSSãããã°æ©èœãå®è£ ããŠããŸãã
ããŒãžã§ã³6以éãã·ã³ãã«ãªJavaScriptãšãã£ã¿ãŒãç»å ŽããŸãããããã¯Firebugã®æ©èœã®1ã€ãå®è£ ããŠããããã©ãŠã¶ãŒã§ã³ãŒããçŽæ¥èšè¿°ããã³å®è¡ã§ããŸãã
ããŒãžã§ã³10ãããããŒãžã®ã€ã³ã¹ãã¯ã¿ãŒãç»å ŽããŸãããããã«ãããHTMLã³ãŒããšCSSããããã£ã調ã¹ãããšãã§ããŸããã€ãŸããHTMLã¿ãã®æ©èœãå®è£ ããŸãã
HTMLã³ãŒãã®æ€èšŒã«ã¯ãéåžžã Html Validatoræ¡åŒµæ©èœã責任ãè² ããŸãã ãµã€ãã®ã¡ã€ã³ããŒãžhabrahabr.ruã®ãšã©ãŒæ°ã瀺ãã¢ã€ã³ã³ã ãããããŒãžã€ã³ã¹ãã¯ã¿ãŒã®ç»åã®ãã©ãŠã¶ãŒã®å³äžé ã«è¡šç€ºãããŸãã
ãŸãããã®æ©äŒãå©çšããŠããã®ãã©ãŠã¶ãŒã«ã¯ç掻ã楜ã«ããå€ãã®æ¡åŒµæ©èœãããããšã瀺ããŸããããã«ã€ããŠã¯ ãHabréã§æ¢ã«å¯Ÿå¿ããèšäºããããŸããã
Google ChromeãšSafari
ãããã®WebKitããŒã¹ã®ãã©ãŠã¶ã«ã¯ãéåžžã«ããéçºãããFirebugãšã»ãŒåãæ©èœãå®è£ ããWeb InspectoréçºããŒã«ãçµã¿èŸŒãŸããŠããŸãã åæã«ãç§ãã¡ã¯åœŒã«æ¬æãæããªããã°ãªããŸããã圌ã¯ãã©ãŠã¶ãé ãããŸãããããã¯ãããã°ãã©ã¶ãŒãã«ããããããšã§ãã
Chromeã§ã¯ã
Ctrl+Shift+I
æŒãããåã«
F12
ã§åŒã³åºãããšãã§ããŸãã Safariã«ã¯é衚瀺ã«ãªã£ãŠããŸãã䜿çšããã«ã¯ããã©ãŠã¶ãŒèšå®ã§éçºæ©èœãæå¹ã«ããå¿ èŠããããŸãã åŸã§ãéçºè ã®ããŒã«ã¯ãã¡ã€ã³ã¡ãã¥ãŒã®
Ctrl+Alt+I
éçº]é ç®ããããŸãã¯ããŒããŒãã·ã§ãŒãã«ããã®
Ctrl+Alt+I
ã§å©çšã§ããããã«ãªããŸã
Ctrl+Alt+I
HTMLã³ãŒããæ€èšŒããã«ã¯ããµãŒãããŒãã£ã®æ¡åŒµæ©èœãã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã ããšãã°ãChromeã®å Žåã Validityã«ãªããŸãã ãããŸã§ã®ãšãããSafariã¯é©åãªãã®ãèŠã€ããããšãã§ããŸããã§ããã
ãªãã©
Operaã«ã¯ãOpera DragonflyããšåŒã°ããçµã¿èŸŒã¿ã®éçºè ããŒã«ããããããŒããŒãã·ã§ãŒãã«ãã
Ctrl+Shift+I
ã䜿çšããŠãã€ã§ãåŒã³åºãããšãã§ããŸã
Ctrl+Shift+I
ããã¯WebKitãè¡šããã®ãšäŒŒãŠãããåæ§ã®æ©èœãšå©ç¹ããããŸãããç§ã®æèŠã§ã¯ããŸã䟿å©ã§ã¯ãããŸããã
åå¿hommã瀺åããããã« ãOperaã«ã¯ãvalidator.w3.orgã«æ€èšŒããŒãžãéä¿¡ããç°¡åãªæ段ããããŸãã ãµã€ãã®è¡šç€ºé åã®ã³ã³ããã¹ãã¡ãã¥ãŒã«ã¯ããWebæšæºã«æºæ ããŠããŸãããšããé ç®ããããŸããããã¯ãŸãã«ããã«è²¬ä»»ããããŸãã
Operaãã£ã¬ã¯ããªã«HTMLæ€èšŒçšã®æ¡åŒµæ©èœããããšãç¶æ³ã¯ç·åŒµããŸãã ãã®ããã Validatoræ¡åŒµã«ã¯ä»£æ¿æ段ããããŸããã
ã€ã³ã¿ãŒããããšã¯ã¹ãããŒã©ãŒ
ããŒãžã§ã³8以éãéçºè ããŒã«ãããã«è¡šç€ºãããŸããã ä»ã®ãã©ãŠã¶ãŒã®å Žåãšã»ãŒåãæ©èœãæäŸããŸãããInternet Explorerã®ã¢ã¯ãã£ããã£ã®ä»ã®åŽé¢ãšåæ§ã«ãInternet Explorerã¯ããã€ãã®æ©èœãšèª¬æã§ããªãã»ã©ã®ç¶äºãæäŸããŸãã éèŠãªãã€ã³ãã¯ãäºæã¢ãŒãã ãã§ãªããå€ãããŒãžã§ã³ããšãã¥ã¬ãŒãããæ©èœã§ãã
ã³ãŒããŒãšJSããã°ã©ããŒã®æ¶ãããŒããããŒãžã§ã³7ã§ã¯ããã®ãããªããŒã«ã¯ååšããªãããšãäžè¬ã«åãå ¥ããããŠããŸãã é¢é£èšäºããã£ããµãŒãããŒãã£ã®ãœãªã¥ãŒã·ã§ã³Companion.JSããããŸã ã ãã¡ããããã®æ©èœã¯éåžžã®ããŒã«ãããããªãå£ããŸããããã®ããŒã«ã䜿çšãããšãå°ãªããšããã¢ã©ãŒãæåãããã°ããããé«åºŠãªã³ãŒãããããã°ã§ããŸãã
åå¿atdã¯ããããã®èŸæ±åŒ·ãããŒãžã§ã³ã«ã¯ãInternet Explorer Developer ToolbarãšåŒã°ããããã€ãã£ããããŒã«ãããããšã瀺åããŸããããåå¥ã®ã€ã³ã¹ããŒã«ãå¿ èŠã§ããïŒ www.microsoft.com/download/en/details.aspx?id=18359
ãŸããåå¿k12thã¯ãVisual Studioãããã°ããã®äžã®ã³ãŒãïŒãWebéçºããŒã«ãã®ã³ã³ããŒãã³ãïŒããããã°ã§ããããšãæãåºããŸããã Visual Web Developer Expressã®ç¡æçã«é¢ããæ å ±ãèŠã€ããããšãã§ããŸãã
ãµãŒããŒã³ãŒãã®ãããã°ãšãããã¡ã€ãªã³ã°
Xdebug
æåã«åæããããã«ããµãŒããŒã§PHPã䜿çšããå Žåãæ€èšããŸãã ããã§ããå€å žçãªããããã°æ¹æ³ã¯
echo
ã
print_r
ãããã³
var_dump
ã§ãããæé«ã®ããŠã¹-Xdebugã®ãããªãããã°ããŒã«ããããŸãã å人çã«ã¯ãç 究æã§ã®å匷ã®è©³çŽ°ã«é¢é£ããŠããDelphiã®ããã«ãèŠããŸããã
xdebugæ¡åŒµã¢ãžã¥ãŒã«ã䜿çšãããšãå°ãªããšãã¹ãããããšã«ã³ãŒããå®è¡ããå€æ°ã®å€ã衚瀺ã§ããŸããããã«ãããPHPããã°ã©ãã³ã°ãæ°ããã¬ãã«ã«åŒãäžããããŸãã xdebugã§ã®äœæ¥ã®è€éãã«ã€ããŠã¯ã察å¿ããèšäºããããŸãã ã XDebugã¯éåžžãGNU / Linuxãªããžããªã§äœ¿çšã§ããŸãããWindowsã§ã¯ãdllãã¡ã€ã«ãã³ããŒããŠã€ã³ã¹ããŒã«ããããšãããã»ã©é£ãããããŸããã
ãã®æ¡åŒµæ©èœã䜿çšããå Žåãçä¿¡æ¥ç¶ïŒããã©ã«ãã§ã¯ããŒã9000ïŒããµãŒããŒããéçºè ã®ã³ââã³ãã¥ãŒã¿ãŒã«å°çãããããåŠçããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãIDEãé©åã«æ§æããå¿ èŠããããŸãã
ãšããã§ãIDEã䜿çšããããšããåé²ããããã®åææ¡ä»¶ã§ãã äžéšã®ããã°ã©ããŒã¯ãã³ãŒããã€ã©ã€ãä»ãã®ã¡ã¢åž³ãšIDEã®ããã°ã©ãã³ã°ã®éãã¯å€§ããªãããžã§ã¯ãã§ããèŠãããªããšèããŠããŸãããå人çã«ã¯ãHello worldïŒããšããããã°ã©ã ã§ãéããèŠãããšæããŸãã ã
XHProf
æ¡åŒµã«ã€ããŠ
ã¯ããxdebugã¯ãããã¡ã€ãªã³ã°æ©èœãæäŸããŸãããç§ã¯å人çã«ãã®ç®çã®ããã®XHProfã® Facebookéçºã奜ãã§ã ã ç§ã¯æ£çŽã«ãã¹ããè¡ã£ãŠããŸããã§ãããããã®æ¡åŒµæ©èœã¯å®çšŒåãµãŒããŒãå®éã®è² è·ã®äžã§ã®ãããã¡ã€ãªã³ã°ã«ã¯ããã«é©ããŠãããšèããããŠããŸãã
èšçœ®
æ®å¿µãªããããã®æ¡åŒµæ©èœã¯ã©ã®ãªããžããªã«ãå«ãŸããŠããŸããã ããã¯PECLã®äžéšã§ãããäœããã®çç±ã§éåžžã®æ¹æ³ã§ã€ã³ã¹ããŒã«ãããšåé¡ãçºçããããšããããããŸãã ãã®ããããœãŒã¹ããã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã
# wget http://pecl.php.net/get/xhprof-0.9.2.tgz # tar -xvf xhprof-0.9.2.tgz # , cd xhprof-0.9.2/extension/ # phpize ./configure make make test # checkinstall
xhprof.ini
æ§æ
xhprof.ini
ã¯ããããã次ã®æ©èœãæäŸããŸãã
[xhprof]
extension=/usr/local/lib/php/extensions/no-debug-non-zts-20090626/xhprof.so
;
xhprof.output_dir="/var/log/xhprof/"
ãããã¡ã€ãªã³ã°
ã¢ãŒã«ã€ãã解åããŠåãåããã£ã¬ã¯ããªã«ã¯ãæ¡åŒµãœãŒã¹ã«å ããŠããããã¡ã€ãªã³ã°çµæã調æ»ããããã®Webã€ã³ã¿ãŒãã§ã€ã¹ãšãã¢ããªã±ãŒã·ã§ã³ããããã¡ã€ãªã³ã°ããããã®ã©ã€ãã©ãªãå«ãŸããŠããŸãã
ãããã¡ã€ãªã³ã°ã®äŸã瀺ããŸãã 次ã®èŠçŽ ãã¢ããªã±ãŒã·ã§ã³ã³ãŒãã«å«ããå¿ èŠããããŸãã
// , // , xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); /* * */ // , , // $xhprofData = xhprof_disable(); include_once XHPROF_DIR.'/xhprof_lib/utils/xhprof_lib.php'; include_once XHPROF_DIR.'/xhprof_lib/utils/xhprof_runs.php'; $xhprofRuns = new XHProfRuns_Default(); $namespace = 'some-unique-name'; $runId = $xhprofRuns->save_run($xhprofData, $namespace); echo "<!-- ", $runId, ' ', $namespace, " -->\n";
ããã§ãå®æ°
XHPROF_DIR
ã¯ãããŠã³ããŒãããã¢ãŒã«ã€ãã解åãããã£ã¬ã¯ããªãæããŸãã
çµæãåæããã«ã¯ãåãWebã€ã³ã¿ãŒãã§ã€ã¹ãå¿ èŠã§ãã
$XHPROF_DIR/xhprof_html/
ã§ååŸã§ããŸã-ãã®ããã«ä»»æã«æå®ããŸãã ããšãã°ãWebãµãŒããŒããã¢ã¯ã»ã¹å¯èœãªå Žæã«é 眮ãã
example.com/system/xhprof/
ã§å©çšã§ã
example.com/system/xhprof/
ãäœæ¥çµæãåæããã«ã¯ã次ã®ããã«ã¢ã¯ã»ã¹ããå¿ èŠããããŸãã
example.com/system/xhprof/?run=%runId%&source=%namespace%
åæ§ã®çµæãåŸãããŸãã
ãããã¡ã€ãªã³ã°ã¯ãç¶ç¶çã«ã¢ããªã±ãŒã·ã§ã³ã³ãŒãã«å«ããããšãã§ããŸãããŸããããšãã°ãç¹å®ã®ç¢ºçã§ããŸãã¯ç¹å®ã®æ¡ä»¶ã®ååšã«ãã£ãŠã©ã³ãã ã«éå§ããããã«äœæããããšãã§ããŸãã ããšãã°ã次ã®ããã«ïŒ
$needProfiler = (mt_rand(0, 100) < 10 or isset($_COOKIE['xhprof'])); if ($needProfiler) xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
ãã®å Žåã顧客ããã®èŠæ ãçããããå Žåãç¹å®ã®æéã®ãããã¡ã€ãªã³ã°çµæãåç §ã§ããŸãã
namespace
ãã©ã¡ãŒã¿ãŒã䜿çšããŠãã¢ããªã±ãŒã·ã§ã³ã®ã©ã®éšåïŒã©ã®ã¹ã¯ãªãããã³ã³ãããŒã©ãŒãã¢ã¯ã·ã§ã³ïŒããããã¡ã€ã«ãããããå€å¥ã§ããŸãã
SQLã¯ãšãªã®ãããã¡ã€ãªã³ã°
ååãšããŠãããŒã¿ããŒã¹ã®æäœã¯ã¢ããªã±ãŒã·ã§ã³ã®ããã«ããã¯ã§ãã ãã®ãããã¯ãšãªãããã¡ã€ãªã³ã°ããå§ãããŸãã ããšãã°ãmysqlæ¡åŒµæ©èœã®ã©ãããŒã§ããã¯ã©ã¹ã®äžéšãèããŸãã ã¯ããç§ã¯åœŒãããã®æ¡åŒµæ©èœãããŸã奜ãã§ã¯ãªããå€ãè¯ãIE6ããã圌ã«æ»ãé¡ã£ãŠããããšãç¥ã£ãŠããŸãã ç§ã¯åœŒã«äœ¿çšããããã«å§ããŸããããã ãã®ã¯ã©ã¹ã¯ç§ã®æå ã«ãŽã£ããã§ãã
/** * * @param string $sql * @param array $params * @param string $query * @return array */ public function query($sql, array $params = array(), &$query = '') { $start = microtime(TRUE); // , "" $stop = microtime(TRUE); $time = $stop - $start; $this->_addProfilerData($sql, $time); // } private function _addProfilerData($query, $time) { if (is_array(self::$profilerData)) { self::$profilerData[] = array( 'query' => $query, 'time' => $time ); } } public function __destruct() { if (is_array(self::$profilerData)) { $this->_writeProfilerData(); self::$profilerData = FALSE; } // } private function _writeProfilerData() { $values = array(); foreach (self::$profilerData as $row) { $query = mysql_real_escape_string($row['query'], $this->con); $time = (float)$row['time']; $hash = crc32($row['query']); $values[] = "($hash, '$query', $time)"; } if ($values) { $strValues = implode(', ', $values); $sql = "INSERT DELAYED INTO `profiler_queries` (`query_hash`, `query`, `work_time`) VALUES $strValues"; @mysql_query($sql, $this->con); } }
ããã§ã¯ãã¯ãšãªãããã¡ã€ãªã³ã°ããŒã¿ã¯
profiler_queries
ããŒãã«ã«ä¿åãããŸãã ãã®ããŒãã«ã¯ãä¿çäžã®æ¿å ¥ãè¡ãæ©èœãæäŸãããããMyISAMãŸãã¯Archiveã¿ã€ãã«ããããšãã§ããŸããããã«ããããããã¡ã€ãªã³ã°æã®å¿çã«äžèŠãªé 延ãçºçããŸããã ãŸããããŒãã«å ã®ã¯ãšãªãããããæ€çŽ¢ããã«ã¯ãã¯ãšãªã®crc32ããã·ã¥ãæžã蟌ãŸãã
INT
åã®åãäœæããããšããå§ãããŸãããã®åã«ã€ã³ããã¯ã¹ãäœæããå¿ èŠããããŸãã
ãããã«
èšäºã¯ããªã倧ããããšãå€æããŸããã ããããç§ã¯ããã«äžã«è¡ã£ãŠããã§ã«è§ŠããããŠãããããã¯ã«è§ŠããŸããããè¿ããã¡ã«äŒŒããããªãã®ãèªãã å Žå-ãã¹ãŠã®æ å ±ãéããããæçšãªãªã³ã¯ãäžããããèšäºã¯ãç§ã«ãšã£ãŠéåžžã«è²Žéã§ãã ç§ã®èšäºããåçºãžã®éã®èª°ããå©ããããšãé¡ã£ãŠããŸãã
åç §è³æ
- ã³ã³ãœãŒã«ãæ倧éã«æŽ»çšããŸã
- FirebugïŒããŒã1-ã³ã³ãœãŒã«
- ãã¹ãŠã®æ©äŒã®ããã®Webéçºã®ããã®Firefoxæ¡åŒµæ©èœ
- IEçšã®JavaScriptãããã¬ãŒ
- xdebugã䜿çšããPHPã¢ããªã±ãŒã·ã§ã³ã®ãããã°
- PHPãããã¡ã€ãªã³ã°
- ãã³ã-ãªã¢ã«ã¿ã€ã phpã¢ãã¿ãªã³ã° ïŒ trueneutralãèŠæ± ïŒ
- Webgrind-Xdebugãããã¡ã€ãªã³ã°Webããã³ããšã³ã ïŒ truezemezæšå¥š ïŒ
- Internet Exploreréçºè ããŒã«ããŒ
- PHPã®XDEBUGæ¡åŒµ
- XHProfïŒGitHubïŒ