ãŸããå¥ã®éèŠãªèŠçŽ ããããŸãã ããã¯ããµãŒããŒäžã§WebããŒãžã圢æãããé床ã§ãã ææ°ã®å€§èŠæš¡ãªãµã€ãã®ã»ãšãã©ã¯ããã¹ãŠã®æ å ±ãããŒã¿ããŒã¹ã«æ ŒçŽããããŸããŸãªèšèªïŒPHPãASPãªã©ïŒã䜿çšããŠãããæœåºããHTMLããŒãžãçæããŠãã©ãŠã¶ãŒã«éä¿¡ããŸãã
ãããã£ãŠããµã€ãã®ããŒãžã1.5ç§ïŒãµã€ããé«éã§ãããšèŠãªãããGoogleã®ãããå€ïŒä»¥äžã§è¿ãããå Žåãåæ§ã«æ€çŽ¢çµæãå«ãããŒãžã®èªã¿èŸŒã¿ã«éåžžã«é·ãæéããããå ŽåããŸãã¯ååã®èª¬æããŒãžã¯ããã«èªã¿èŸŒãŸããŸããããŠãŒã¶ãŒã¬ãã¥ãŒã¯æ°ç§éèªã¿èŸŒãŸããŸãã
ãé«éããŠã§ããµã€ããèå¥ããããã«Googleãèšå®ãããããå€ã¯ãçŽ1.5ç§ã§ãã ãŠã§ããã¹ã¿ãŒããŒã«ã®åæ§ã®ã¹ã±ãžã¥ãŒã«ãååŸã§ããŸãïŒ[ãã¡ã€ã³]â蚺æâããã©ãŒãã³ã¹ã«ç§»åïŒã
ãã®èšäºã§ã¯ãåæ§ã®åé¡ã«ã€ããŠèª¬æããããŒã¿ããŒã¹ãæé©åããŠãµã€ããé«éåããããã€ãã®æ¹æ³ã«ã€ããŠèª¬æããŸãã ããè€éãªã¡ãœããã®èª¬æãªã©ãããç¥ãããäºå®ããå§ãŸããããã«åç §ããããã®ãªãœãŒã¹ã®ãªã¹ããå«ãŸããŠããŸãã ãã®èšäºã¯ã倧èäžæµãªåå¿è ãšãçªçºè¡çºãè¡ãéçºè ã察象ãšããŠããŸãã
ããŒã¿ããŒã¹ãšã¯äœã§ããïŒ SQLãšã¯äœã§ããïŒ
äžè¬ã«ãããŒã¿ããŒã¹ã¯ãããšãã°é¡§å®¢ãšãã®æ³šæã®ãªã¹ããªã©ã®æ å ±ãå«ãããŒãã«ã®ã»ããã§ãã ããã«ã¯ããã¡ã€ã«ãã£ãããããå€æ°ã®ã¹ãã¬ããã·ãŒããMicrosoft Accessãã¡ã€ã«ããŸãã¯40ãã©ãã€ãã®Amazonããã¯ãšã¯ã©ã€ã¢ã³ãããŒã¿ããããŸã ã
äžè¬çãªããã°ããŒã¿ããŒã¹ã«ã¯ããŠãŒã¶ãŒãã«ããŽãªãæçš¿ãã³ã¡ã³ãã«é¢ããæ å ±ãå«ãããŒãã«ãå«ãŸããŠããŸãã Wordpressã«ã¯ãæåã«ããããšä»ã®ããã€ãã®ããŒãã«ããããŸãã eã³ããŒã¹ã·ã¹ãã ã®ããŒã¿ããŒã¹ã«ã¯ãããã¹ã±ãããã«å«ãŸãã顧客ã補åãã«ããŽãªã泚æã補åã«é¢ããæ å ±ãå«ãããŒãã«ãå«ãŸããŠããŸãã ãªãŒãã³Magentoãšã³ãžã³ã«ã¯ã ãããã®ããŒãã«ãšä»ã®å€ãã®ããŒãã«ãå«ãŸããŠããŸãã ããŒã¿ããŒã¹ã«ã¯ãã³ã³ãã³ãã®ç®¡çã顧客é¢ä¿ãã¢ã«ãŠã³ããšè«æ±æžãã€ãã³ãã®ä¿åãªã©ãå€ãã®ã¢ããªã±ãŒã·ã§ã³ã®å¯èœæ§ããããŸãããããã®ã¿ã€ãïŒããã°ãšeã³ããŒã¹ãµã€ãã®ãšã³ããªïŒã®äž¡æ¹ããã®èšäºã«æ²èŒãããŸãã
ããŒã¿ããŒã¹å ã®äžéšã®ããŒãã«ã¯ãä»ã®ããŒãã«ã«é¢é£ä»ããããŠããŸãã ããšãã°ãããã°ã®æçš¿ã«ã¯è€æ°ã®ã³ã¡ã³ããå«ãŸããã¯ã©ã€ã¢ã³ãã¯è€æ°ã®æ³šæãè¡ãããšããããŸãïŒããã¯1察å€ã®é¢ä¿ã§ãïŒã ããŒã¿ããŒã¹ã§æãè€éãªé¢ä¿ã®åœ¢åŒã¯ãå€å¯Ÿå€ã®é¢ä¿ã§ãã ãã®çš®ã®é¢ä¿ã¯ãeã³ããŒã¹ã·ã¹ãã ã®ããŒã¿ããŒã¹ã®äžæ žã§ãã1ã€ã®æ³šæã«ç°ãªã補åãå«ããããšãã§ããŸãã補åãç°ãªã泚æã«å«ãŸããã®ãšåãã§ãã ããã¯ã泚æãšååã®éã«ããã泚æå 容ãããŒãã«ã衚瀺ãããå Žæã§ããããŠãŒã¶ãŒãååã泚æã«è¿œå ãããã³ã«èšé²ãããŸãã ãããã©ãã»ã©éèŠã§ãããã¯ãåŸã§ããã€ãã®ã¯ãšãªãé·æéå®è¡ãããçç±ãèãããšãã«ç解ãããŸãã
ããŒã¿ããŒã¹ã¯ããã®ãã¹ãŠã®ããŒã¿ãå«ããœãããŠã§ã¢ãæããŸãã ãœãããŠã§ã¢ãšã¯ããä»æ¥ã¯æé£ãé£ã¹ãŠããéã«ãããŒã¿ããŒã¹ããèœã¡ãŸãããããŸãã¯ãããŒã¿ããŒã¹ãæŽæ°ããå¿ èŠãããããšããæå³ã§ãã ïŒ ãããã¯ããŒã¿ããŒã¹ã§ã¯ãªããDBMSãæããŠããå¯èœæ§ãé«ãããšç¿»èš³è ã¯èšããŸããïŒ:) ãäžè¬çãªã·ã¹ãã ã¯ãMicrosoft Access 2010ãMicrosoft SQL ServerãMySQLãPostgreSQLãOracle Database 11gã§ãã
SQLã®ç¥èªã¯ãããŒã¿ããŒã¹ã«é¢ããŠã¯ãã°ãã°èšåãããŸãã ãStructured Query LanguageãïŒæ§é åç §äŒèšèªïŒãšãããã¬ãŒãºã«ç±æ¥ãããEs-Kyu-Elããšçºé³ãããŸãïŒ ãYaZZããœé£ã§éçºãããå Žåãããšç¿»èš³è ã¯èšããŸããïŒ:ïŒ ãé©ãã¹ãæ¹æ³ã§ããŒã¿ããŒã¹ã䜿ã£ãŠïŒ
SELECT lastname FROM customers WHERE city='Brighton';
ãã®ã³ãŒãã¯ãªã¯ãšã¹ããšåŒã°ããŸãã INSERT ïŒããŒã¿ã®è¿œå çšïŒã UPDATE ïŒæŽæ°çšïŒã DELETE ïŒåé€çšïŒã CREATE TABLE ïŒããŒãã«äœæçšïŒã ALTER TABLEãªã©ãããŒã¿ããŒã¹ãæäœããä»ã®åŒããããŸãã
ããŒã¿ããŒã¹ã¯ã©ã®ããã«ãµã€ããé ãããããšãã§ããŸããïŒ
æ°ãã空ã®ãµã€ãã¯éåžžã«è¿ éã«æ©èœããŸããããããžã§ã¯ãã®éçºã«äŒŽããç¹å®ã®ããŒãžãç¹ã«æ©èœã®è€éãªèŠçŽ ãæã€ããŒãžã§ããã¬ãŒãããçºçããããšããããŸãã 補åãªã¹ãããŒãžã®äžéšã«ããã®è£œåã§ä»ã«äœãè³Œå ¥ããŸãã...ããšè¡šç€ºãããšããŸãã ããŒã¿ããŒã¹ãããã®æ å ±ãååŸããã«ã¯ã次ã®æé ãå®è¡ããå¿ èŠããããŸãã
- ãäœæ¥ããã補åãç¹å®ããŸãã
- ãã®è£œåã顧客ã«ãã£ãŠããã¹ã±ãããã«è¿œå ãããååã®åæ°ïŒäžèšã®ã泚æå 容ãã®è¡šïŒã確èªããŸãã
- åã泚æã§ããã¹ã±ãããã«è¿œå ããã補åã®ãªã¹ããååŸããŸãïŒç¢ºèªæžã¿ã®æ³šæã®ã¿ïŒã
- ãããã®æ³šæãè¡ã£ãè³Œå ¥è ãéžæããŠãã ããã
- ãŠãŒã¶ãŒãäžèšã®ã¢ã€ãã ããè¡ã£ã泚æãéžæããŸãã
- 泚æã®å 容ã確èªããŸãïŒåãè¡šã泚æå 容ãïŒã
- ãããã®è£œåã«é¢ããæ å ±ãå ¥æããŠãã ããã
- ãããã®æ³šæã§ããäžè¬çãªè£œåãç¹å®ãããã®ãªã¹ãã衚瀺ããŸãã
1ã€ã®è€éãªã¯ãšãªã«ãã¹ãŠãåããããšããããã€ãã®åçŽãªã¯ãšãªã«åå²ããããšãã§ããŸãã ãããã®å Žåã§ããããŒã¿ããŒã¹ã«20åã®è£œåã12åã®é¡§å®¢ã18åã®æ³šæã67åã®è³Œå ¥åïŒããã¹ã±ãããå ã®è£œåã®åèšæ°ïŒãå«ãŸããŠããå Žåãéåžžã«è¿ éã«å®äºã§ããŸãã ãããããã¹ãŠãéå¹ççã«è¡ããããšããã®ãããªæäœã®å®è¡ã¯å€§éã®ããŒã¿ã«å¯ŸããŠéåžžã«é ããªããŸãã ããšãã°ã500ã®è£œåã10,000ã®é¡§å®¢ã14,000ã®æ³šæã100,000ã®è³Œå ¥ããååãåŠçãããšãããŒãžã®èªã¿èŸŒã¿ãé ããªããŸãã
ããã¯éåžžã«è€éãªäŸã§ããããèå°è£ãã§äœãèµ·ãã£ãŠããã®ãããããŠç¡å®³ã«èŠããæ©èœã®èŠçŽ ããµã€ãã«ã眮ããããçç±ãæ³åããããšãã§ããŸãã
ãµã€ãã®ã¹ããŒããŠã³ã¯ãä»ã®çç±ã«ãã£ãŠåŒãèµ·ããããå¯èœæ§ããããŸãããµãŒããŒãååãªã¡ã¢ãªãŸãã¯ãã£ã¹ã¯ã¹ããŒã¹ã§å®è¡ãããŠããªãã ãã®ãµãŒããŒäžã®å¥ã®ãµã€ãã¯å€ãã®ãªãœãŒã¹ãæ¶è²»ããŸãã ãµãŒããŒãé»åã¡ãŒã«ãéä¿¡ããŠããããä»ã®ãéããã¿ã¹ã¯ã§ããžãŒã§ãã ãœãããŠã§ã¢ãŸãã¯ããŒããŠã§ã¢ã®ãšã©ãŒã ééã£ãæ§æã ãããã人æ°ãããããã®çµæããµã€ããžã®ãã©ãã£ãã¯ãçªç¶å¢å ããã®ã§ããããïŒ æ¬¡ã®2ã€ã®ã»ã¯ã·ã§ã³ã§ã¯ãäœæ¥ã®é床ãããã«è©³ããæ€èšããŸãã
ããŒã¿ããŒã¹ã®å ŽåïŒ
çŸåšã Firefoxã®Firebugãã©ã°ã€ã³ ãGoogle Chromeã®éçºè åãããŒã«ïŒShift + Ctrl + Iã以äžãªãœãŒã¹âãªãœãŒã¹ãã©ããã³ã°ãæå¹ã«ããïŒã Yahoo YSlowãªã©ããµã€ãã®é床ãåæããæ¹æ³ãããã€ããããŸãã WebPagetestã®ãããªç¹å¥ãªãµã€ãããããããã§URLãå ¥åãããšãæå®ãããå Žæããé床ã枬å®ããŸãã
ãããã®ããŒã«ã¯ãããŒãžã§äœ¿çšå¯èœãªãã¹ãŠã®ãªãœãŒã¹ïŒHTMLãç»åãCSSãããã³JavaScriptãã¡ã€ã«ïŒã®å³ã衚瀺ããããããã®èªã¿èŸŒã¿æéã瀺ããŸãã ãããã®ããŒã«ã¯ã以äžã«è²»ããæéã決å®ããŸãã
- DNSã¯ãšãªïŒãã¡ã€ã³åããIPã¢ãã¬ã¹ãžã®å€æïŒã
- ãµãŒããŒãžã®æ¥ç¶
- ãµãŒããŒããã®å¿çãåŸ ã£ãŠããŸãïŒãæåã®ãã€ããŸã§ã®æéããå¥åTTFB-æåã®ãã€ããŸã§ã®æéïŒã³ã¡ã³ãå€æïŒïŒã
- ãµãŒããŒããããŒã¿ãåä¿¡ïŒããŠã³ããŒãïŒããŸãã
ããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ããããã«ãã¹ãŠããã©ãŠã¶ãŒã«éä¿¡ããPHPãå«ãå€ãã®WebããŒãžã¯ãµãŒããŒäžã§å®å šã«çµã¿ç«ãŠãããŸãããã®ãããããŒã¿ããŒã¹ã®é 延ã¯é·ãåŸ æ©æéã«ã€ãªãããããŒã¿ã®åä¿¡/ããŠã³ããŒãæéã¯ããªã¥ãŒã ã«æ¯äŸããŸãã ã ãããã£ãŠãé«éæ¥ç¶ã§ã¯ã5ç§ã§åœ¢æããã20 KBã®WebããŒãžïŒ0.05ç§ã§ããŒãããŸããïŒã«ããããµãŒããŒã§å€§ããªé 延ãçºçããŸãã
ããã§ãããã¹ãŠã®ããŒãžãããã§ãããšã¯éããŸããã PHPé¢æ°flushïŒïŒã¯ãæ¢ã«çæãããHTMLããŒã¿ããã©ãŠã¶ãŒã«éä¿¡ããŸãã ãã以äžã®é 延ã¯ããã®ããŒã¿ã®ããŒãã«ãã§ã«é¢é£ä»ããããŠãããäºæ³ã«ã¯é¢é£ä»ããããŠããŸããã
ãããã®å Žåã§ããåããµãŒããŒäžã«ãããããããäœéã§è€éãªWebããŒãžã®åŸ æ©æé/ããŒãæéãšãåããµã€ãºã®HTMLããŒãžïŒãŸãã¯ç»åããã®ä»ã®éçèŠçŽ ïŒã®åŸ æ©æéãåæã«æ¯èŒã§ããŸãã ããã«ãããäœéãªã€ã³ã¿ãŒãããæ¥ç¶ããµãŒããŒè² è·ïŒãããã®ãªãã·ã§ã³ã®äž¡æ¹ãé 延ãåŒãèµ·ããå¯èœæ§ããããŸãïŒã®åœ±é¿ãæé€ãããããŒãžã®åœ¢æã«è²»ãããããããã®æéãæ¯èŒã§ããŸãã ãã¡ãããããã¯æ£ç¢ºãªç§åŠã§ã¯ãããŸããããäœãã©ãã§æžéãããã«ã€ããŠã®ããã€ãã®ã¢ã€ãã¢ãæäŸããŸãã
以äžã®ã¹ã¯ãªãŒã³ã·ã§ããã¯ãGoogle Chrome WebããŒãžã§ã®éçºè ããŒã«ã«ããåæã®çµæãšãåããµã€ãºïŒ20 KbïŒã®ç»åã瀺ããŠããŸãã WebããŒãžã®åŸ æ©æéã¯130ããªç§ãããŠã³ããŒãæéã¯22ããªç§ã§ããã ç»åã®æéã¯ããããã51ããªç§ãš11ããªç§ã§ãã ããŠã³ããŒãæéã¯ã»ãŒåãã§ããããµãŒããŒã¯WebããŒãžã®åŠçãšçæã«ããã«80ããªç§ããããŸãããããã¯ãPHPã³ãŒãã®å®è¡ãšããŒã¿ããŒã¹ãšã®çžäºäœçšã®çµæã§ãã
ãããã®ãã¹ããå®è¡ãããšãã¯ãéçã³ã³ãã³ããåæããªããããã£ãã·ã¥ããŒãžã§ã³ãååŸããªãããã«ããŒãžãæŽæ°ããŸãã ããã«ããã¹ããæ°åå®è¡ããŠãçµ±èšäžã®éžè±ã«çŽé¢ããŠããªãããšã確èªããŸãã 以äžã®3çªç®ã®ã¹ã¯ãªãŒã³ã·ã§ããã¯ãWebPagetestãåãããŒãžã§åæã«Googleã®ããŒã«ã®ã»ãŒ2åã®æéã衚瀺ããããšã瀺ããŠããŸãã ããã¯ããã¹ããå®è¡ãããšãã«ããããã®ããŒã«ã䜿çšããå¿ èŠãããããšã瀺åããŠããŸãã
Google ChromeããŒã«ãããã䜿çšãããšãWebããŒãžã®èªã¿èŸŒã¿æã«130ããªç§ãåŸãããŸã
åãããŒã«ã åæ§ã®ãµã€ãºã®ç»åãèªã¿èŸŒãå Žåã51 msããããŸã
WebPagetestã§åãããŒãžãåæãããšãåŸ æ©æéã296ããªç§ãåèšããŠã³ããŒãæéã417ããªç§ã«ãªããŸã
MySQL / PHPã§ã¯ãšãªã枬å®ããŸããïŒ
äžè¬çãªã¢ã€ãã¢ãåãåã£ãã®ã§ããã詳现ã«ç解ããŸãã ããŒã¿ããŒã¹ããµã€ãã®é床ãäœäžãããŠããçããããå Žåã¯ãé 延ã®åå ãæ£ç¢ºã«ç¹å®ããå¿ èŠããããŸãã åããŒã¿ããŒã¹ã¯ãšãªã®å®è¡æéãèšç®ããé¢æ°ãããã€ãå®çŸ©ããŸãã ãã®ã³ãŒãã¯PHP / MySQLçšã§ããããã®ã¡ãœããã¯ããŒã¿ããŒã¹ã䜿çšãããã¹ãŠã®Webãµã€ãã§äœ¿çšã§ããŸãã
function StartTimer ($what='') { global $MYTIMER; $MYTIMER=0; //global variable to store time //if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') return; //only show for my IP address echo '<p style="border:1px solid black; color: black; background: yellow;">'; echo "About to run <i>$what</i>. "; flush(); //output this to the browser //$MYTIMER = microtime (true); //in PHP5 you need only this line to get the time list ($usec, $sec) = explode (' ', microtime()); $MYTIMER = ((float) $usec + (float) $sec); //set the timer } function StopTimer() { global $MYTIMER; if (!$MYTIMER) return; //no timer has been started list ($usec, $sec) = explode (' ', microtime()); //get the current time $MYTIMER = ((float) $usec + (float) $sec) - $MYTIMER; //the time taken in milliseconds echo 'Took ' . number_format ($MYTIMER, 4) . ' seconds.</p>'; flush(); }
StartTimerã¯ã¿ã€ããŒãéå§ãã枬å®ãããã¹ãŠã衚瀺ããŸãã 2è¡ç®ã¯IPã¢ãã¬ã¹ã確èªããŠããŸãã ããã¯ãäœæ¥äžã®ãµã€ãã§ïŒäžæçã«ïŒæž¬å®ãè¡ãããã®ãããªçµ±èšãå šå¡ã«èŠããããªãå Žåã«åœ¹ç«ã¡ãŸãã æåã®//ãåé€ããŠè¡ã®ã³ã¡ã³ãã解é€ãã 127.0.0.1ãIPã¢ãã¬ã¹ã«çœ®ãæããŸã ã StopTimerã¯ã¿ã€ããŒãåæ¢ããçµéæéã衚瀺ããŸãã
ææ°ã®ãµã€ãïŒç¹ã«ããã§ãããªãŒãã³ãœãŒã¹ãããžã§ã¯ãïŒã®å€ãã¯ãå€ãã®PHPãã¡ã€ã«ãæã£ãŠããŸãããããŒã¿ããŒã¹ã¯ãšãªã¯ãããã®äžéšã§ã®ã¿å®è¡ãããŸãã ãããã®ãã¡ã€ã«ã§mysql_db_queryãŸãã¯mysql_queryè¡ãæ¢ããŸãã BBEditãªã©ã®å€ãã®ãœãããŠã§ã¢éçºã«ã¯ããã®çš®ã®æ€çŽ¢ãå®è¡ã§ããæ©èœããããŸãã Linuxã³ã³ãœãŒã«ã«ç²ŸéããŠããå Žåã¯ã次ã®ã³ãã³ããè©ŠããŠãã ããã
grep mysql_query `find . -name \*php`
çµæã¯æ¬¡ã®ããã«ãªããŸãã
mysql_query ($sql);
WordPress 3.0.4ã®å Žåãããã¯wp-includes / wp-db.phpãã¡ã€ã«ã® 1112è¡ç®ã«ãªããŸã ã äžèšã®é¢æ°ããã¡ã€ã«ã®å é ïŒãŸãã¯åããŒãžã«æ¥ç¶ãããã¡ã€ã«ïŒã«ã³ããŒãã mysql_queryè¡ã®ååŸã«StartTimerããã³StopTimeré¢æ°ãè¿œå ããŠããããååŸã§ããŸãã
StartTimer ($query); $this->result = @mysql_query( $query, $dbh ); StopTimer();
以äžã®ã¹ã¯ãªãŒã³ã·ã§ããã¯ãWordPressãã€ã³ã¹ããŒã«ããçŽåŸã«ã³ãŒããè¿œå ããçµæã瀺ããŠããŸãã åèšã§ã15件ã®ãªã¯ãšã¹ããåŠçãããããããçŽ0.0003ç§ããããŸãã ïŒ0.3 msïŒã空ã®ããŒã¿ããŒã¹ããäºæ³ãããŸãã
ããã«ãã¹ãŠã®WordPressãªã¯ãšã¹ãã衚瀺ããã枬å®ãããŸãã
ä»ã®åºã䜿çšãããŠããã·ã¹ãã ã§ãã®è¡ãèŠã€ããå Žåã¯ããã®èšäºã«ã³ã¡ã³ããè¿œå ããŠãã®æ å ±ãå ±æããŠãã ããã
ä»ã®é¢çœãããšãããããšãã§ããŸãïŒããªãã®ã³ã³ãã¥ãŒã¿ãŒãç§ã®ã³ã³ãã¥ãŒã¿ãŒãšæ¯èŒããŠã©ããããéãããèŠãããšãã§ããŸãã ç§ã®ã³ã³ãã¥ãŒã¿ãŒã§ã¯1.000.000ãžã®ãã«ãŠã³ãããŠã³ãã«ã¯2.9420ç§ããããŸããããµãŒããŒã¯2.0726ç§ãšå°ãé«éã§ãã
StartTimer ('counting to 10000000'); for ($i=0; $i<10000000; $i++); //count to a high number StopTimer();
çµæã«ã€ããŠã®äœãã
ãã®æ¹æ³ã§ã¯ãæ¯èŒçµæã®ã¿ãåŸãããŸãã ãµãŒããŒããã®æç¹ã§ããžãŒã ã£ãå Žåããã¹ãŠã®ãªã¯ãšã¹ãã¯éåžžââãããé ããªããŸããã ãã ããå°ãªããšããé«éããªã¯ãšã¹ãã®å®è¡æéïŒ1ã5ããªç§ïŒãäœéïŒ200ããªç§ä»¥äžïŒãããã³æããéããïŒ1ç§ä»¥äžïŒãå€æã§ããã¯ãã§ãã ãã®ãã¹ãã1æéãŸãã¯1æ¥äžã«æ°åå®è¡ã§ããŸãïŒãã ããåã®ãã¹ãã®çŽåŸã§ã¯ãããŸãã-ããŒã¿ããŒã¹ãã£ãã·ã¥ã®ã»ã¯ã·ã§ã³ãåç §ïŒã
ãŸããWebããŒãžã®ãã¶ã€ã³ãæ·±å»ã«æãªãå¯èœæ§ããããŸãã ãããããŒæ å ±ãå€æŽã§ããŸããã ããããŒã¯ãã§ã«...ã§éä¿¡ãããŠããŸãã ããã¯ã枬å®ã¡ãã»ãŒãžãCookieããã³ã»ãã·ã§ã³ããããŒãããå ã«ããããã§ãã ããŒãžã®ã¡ã€ã³ã³ã³ãã³ãã衚瀺ãããŠããå Žåããããã®ã¡ãã»ãŒãžã¯ç¡èŠã§ããŸãã ããŒãžã空çœã®å Žåã mysql_queryã®åšãã§ã¯ãªããç¹å®ã®ã³ãŒããããã¯ã®åšãã§StartTimerããã³StopTimeré¢æ°ã宣èšããå¿ èŠããããŸãã
ãã®æ¹æ³ã¯ã倧ãŸããªçµæãåŸãããã®éåžžã«ç°¡åãªæ¹æ³ã§ãããå®éã®Webãµã€ãã«æ®ããªãã§ãã ããã
ä»ã«äœãåå ã§ããããïŒ
ããŒã¿ããŒã¹ã®ã¯ãšãªãããã»ã©é ããªãå Žåã§ããããŒãžãé·æéã«ããã£ãŠåœ¢æãããå Žåããã®åå ã¯ã³ãŒãã®èšè¿°ãäžååã§ããå¯èœæ§ãé«ãã§ãã ã³ãŒãã®å€§éšåã«ã¿ã€ããŒé¢æ°ãè¿œå ããŠãé 延ããããã©ããã確èªã§ããŸããïŒ ãã¶ããã®çç±ã¯ã20é ç®ãã衚瀺ããŠããªããŠãã10,000è¡ã®æ å ±ã調ã¹ãŠããããã§ããããïŒ
ãããã¡ã€ãªã³ã°
ããã§ãæ··ä¹±ããŠããå Žåãããã³/ãŸãã¯ã³ãŒãã§äœãè¡ãããŠãããã«ã€ããŠã®è©³çŽ°æ å ±ãååŸãããå Žåã¯ããµã€ãã®ããŒã«ã«ã³ããŒãåæããXdebugãªã©ã®ããŸããŸãªãããã°ããã³ãããã¡ã€ãªã³ã°ããŒã«ãè©ŠããŠãã ããã ãã¹ãŠã®ããã«ããã¯ãèŠèŠçã«è¡šç€ºããããšãã§ããŸãã
ã€ã³ããã¯ã¹ããŒãã«
äžèšã®å®éšã§ã¯ãããŒãžããŒã¿ããŒã¹ããµã€ãäžã§æã£ãŠããã¯ãšãªã®æ°ã瀺ãããšã§é©ããããããŸãããé ãã¯ãšãªãç¹å®ããã®ã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã
ããã»ã¹ãé«éåããããã«ãããã€ãã®ç°¡åãªæ©èœåŒ·åãèŠãŠã¿ãŸãããã ãããè¡ãã«ã¯ãäœããã®åœ¢ã§ãªã¯ãšã¹ããããŒã¿ããŒã¹ã«çŽæ¥éä¿¡ããå¿ èŠããããŸãã å€ãã®ãµãŒããŒç®¡çããã±ãŒãžïŒCPanelãPleskãªã©ïŒã«PhpMyAdminãä»å±ããŠãããåæ§ã®ã¿ã¹ã¯ãå®è¡ã§ããŸãã ããã«ã phpMiniAdminã®ãããªãã®ããµã€ãã«ã¢ããããŒãã§ããŸããããŒã¿ããŒã¹ã衚瀺ããŠã¯ãšãªãå®è¡ã§ããPHPãã¡ã€ã«ã¯1ã€ã ãã§ãã ããŒã¿ããŒã¹åããŠãŒã¶ãŒåããã¹ã¯ãŒããå ¥åããå¿ èŠããããŸãã ããããããããªãå Žåã¯ããµã€ãã®æ§æãã¡ã€ã«ã§ç°¡åã«èŠã€ããããšãã§ããŸãïŒããšãã°ãWordPressã®å Žåãããã¯WP-config.phpã§ãïŒã
ãµã€ãããŒãžãå«ãããŒã¿ããŒã¹ã¯ãšãªã®äžã§ãããããWHEREã§æ¡ä»¶ãèŠãŸããã ããã¯ãSQLã䜿çšããŠçµæããã£ã«ã¿ãªã³ã°ããæ¹æ³ã§ãã ããšãã°ããµã€ãã§ãè³Œå ¥å±¥æŽãããŒãžã衚瀺ããŠããå Žåããããã誰ã泚æããããç¹å®ããã¯ãšãªããããŸãã ãã®ãããªãã®ïŒ
SELECT * FROM orders WHERE customerid = 2;
ãã®èŠæ±ã¯ãã¯ã©ã€ã¢ã³ããID 2ã§è¡ã£ããã¹ãŠã®æ³šæãååŸããŸãã100,000件ã®æ³šæã¬ã³ãŒããããã³ã³ãã¥ãŒã¿ãŒã§ã¯ã0.2158ç§ããããŸãã
WHEREã®æ¡ä»¶ã§äœ¿çšãããå¯èœæ§ã®ããå€ãã®å€ãå«ãCustomerIDãªã©ã®åã¯ã =ãŸãã¯< ããŸãã¯>ãšçµã¿åãããŠãã€ã³ããã¯ã¹ãäœæããå¿ èŠããããŸãã ããã¯ãæ¬ã®æåŸã®å 容ã®ãããªãã®ã§ããããŒã¿ããŒã¹ãã€ã³ããã¯ã¹ä»ãããŒã¿ããã°ããååŸããã®ã«åœ¹ç«ã¡ãŸãã ããã¯ãããŒã¿ããŒã¹ã¯ãšãªãé«éåããæãéãæ¹æ³ã®1ã€ã§ãã
ã€ã³ããã¯ã¹ãäœæãããã®
ã€ã³ããã¯ã¹ãäœæããåãèŠã€ããã«ã¯ãããŒã¿ããŒã¹ã®äžè¬çãªäœ¿çšæ¹æ³ãææ¡ããå¿ èŠããããŸãã ããšãã°ãååã§ã«ããŽãªãæ€çŽ¢ããããæ¥ä»ã§ã€ãã³ããæ€çŽ¢ããããã«ãµã€ãããã䜿çšãããå Žåã¯ããããã®åã«ã€ã³ããã¯ã¹ãä»ããå¿ èŠããããŸãã
SELECT * FROM categories WHERE name = 'Books'; SELECT * FROM events WHERE startdate >= '2011-02-07';
åããŒã¿ããŒã¹ããŒãã«ã«ã¯ã以äžã®wp_postsããŒãã«ã®ã¹ã¯ãªãŒã³ã·ã§ããã®ããã«ã äž»ããŒãšããŠç€ºãããèå¥ååïŒéåžžã¯idã§ããã IDãŸãã¯ArticleIDãªã©ïŒãå¿ èŠã§ãã ãããã®äž»ããŒã¯èªåçã«ã€ã³ããã¯ã¹ä»ããããŸãã ãã ããäžèšã®äŸã®CustomerIDãªã©ãä»ã®ããŒãã«ã®èå¥åãåç §ããåã«ãã€ã³ããã¯ã¹ãä»ããå¿ èŠããããŸãã ãã®å Žåããããã¯å€éšããŒã«ãªããŸã ã
SELECT * FROM orders WHERE customerid = 2; SELECT * FROM orderitems WHERE orderid = 231;
ååã®èª¬æãèšäºã®å 容ãªã©ã倧éã®ããã¹ãããŒã¿ãæ€çŽ¢ããå¿ èŠãããå Žåã¯ãå¥ã®çš®é¡ã®ã€ã³ããã¯ã¹-FULL TEXTãè¿œå ã§ããŸãã ã¿ã€ãFULL TEXTã®ã€ã³ããã¯ã¹ã䜿çšããã¯ãšãªã¯è€æ°ã®åã«ãŸãããããšãã§ããæåã¯4æåããé·ãåèªã«å¯Ÿå¿ããããã«æ§æãããŠããŸãã ã¹ãããã¯ãŒãããã³ã€ã³ããã¯ã¹åããããšã³ããªã®50ïŒ ä»¥äžã§èŠã€ãã£ãã¯ãŒããé€å€ãããŸãã ãã ãããã®ã¿ã€ãã®ã€ã³ããã¯ã¹ã䜿çšããã«ã¯ãSQLã¯ãšãªãå€æŽããå¿ èŠããããŸãã 以äžã¯ã FULL TEXTã€ã³ããã¯ã¹ã䜿çšããå Žåãšäœ¿çšããªãå Žåã®ã¯ãšãªã§ãã
SELECT * FROM products WHERE name LIKE '%shoe%' OR description LIKE '%shoe%'; SELECT * FROM products WHERE MATCH(name,description) AGAINST ('shoe');
ãã®æ¹æ³ã§ãã¹ãŠã®ã€ã³ããã¯ã¹ãäœæããå¿ èŠãããããã«æããããããããŸããã ãã ããã€ã³ããã¯ã¹ä»ãã«ãã£ãŠéžæã¯é«éåãããŸããã æ¿å ¥ ã æŽæ° ã åé€ã®æäœã¯é ããªããŸãã ãããã£ãŠãé »ç¹ã«å€æŽãããå¯èœæ§ã®äœãååã®èª¬æãå«ãããŒãã«ãããå Žåã¯ãã€ã³ããã¯ã¹ãäœæã§ããŸãã ãã ããé åºä»ãã®ããŒãã«ã¯åžžã«å€æŽãããå¯èœæ§ããããŸãããã®å Žåãã€ã³ããã¯ã¹äœæã«æ³šæããå¿ èŠããããŸãã
ãŸãã 玢åŒä»ãã圹ã«ç«ããªãå Žåã«ã泚æããå¿ èŠããããŸã ã ããšãã°ãåã®ã»ãšãã©ã®å€ãåãå€ãæã€å Žåã ãåšåº«ããæå³ãã補åã¹ããŒã¿ã¹åã§å€ã1ãã䜿çšããããã¹ãŠã®ååã®95ïŒ ããåšåº«ãã§ããå Žåãã€ã³ããã¯ã¹ã¯åšåº«ã®ååãèŠã€ããã®ã«åœ¹ç«ã¡ãŸããã æ¬ã®æåŸã§èšãèš³ãžã®ãã€ã³ã¿ãäœæããªããã°ãªããªãå Žåããªã³ã¯ã¯ãã®ãã¹ãŠã®ããŒãžã«ç§»åããŸãã
SELECT * FROM products WHERE stock_status = 1;
ã€ã³ããã¯ã¹ãäœæããæ¹æ³ã¯ïŒ
PhpMyAdminãŸãã¯phpMiniAdminã䜿çšããŠãåããŒãã«ã®æ§é ã調ã¹ãåã«ã€ã³ããã¯ã¹ãä»ããããŠãããã©ããã確èªã§ããŸãã PhpMyAdminã§ããŒãã«åãéžæããŸããæ§é ã®æåŸã«ã€ã³ããã¯ã¹ã®åæããããŸãã phpMiniAdminã§ãäžéšã«ãã[ããŒãã«ã®è¡šç€º]ãã¯ãªãã¯ããŠãããå¿ èŠãªããŒãã«ã®å察åŽã®[sct] ïŒããŒãã«ã®äœæã衚瀺ïŒãã¯ãªãã¯ããŸãã ãããã®ã¢ã¯ã·ã§ã³ã®çµæãšããŠãããŒãã«ã®äœæã«å¿ èŠãªã¯ãšãªã衚瀺ããããã®æåŸã«æ¬¡ã®ãããªã€ã³ããã¯ã¹ã®ãªã¹ãã衚瀺ãããŸãã
orderidindex" KEY ("orderid");
PhpMiniAdminã䜿çšããŠãWordPressã®wp_postsããŒãã«ã®ã€ã³ããã¯ã¹ã®ãªã¹ãã衚瀺ããŸã
ã€ã³ããã¯ã¹ããªãå Žåã¯ãèªåã§äœæã§ããŸãã PhpMyAdminã®[ã€ã³ããã¯ã¹]ã»ã¯ã·ã§ã³ã§ãã€ã³ããã¯ã¹ãäœæããåã®æ°ãæå®ãã[å®è¡]ãã¯ãªãã¯ããŸãã 以äžã®ã¹ã¯ãªãŒã³ã·ã§ããã«ç€ºãããã«ãã€ã³ããã¯ã¹ã®ååãå ¥åããå¿ èŠãªåãéžæããŠãä¿åããã¯ãªãã¯ããŸãã
PhpMyAdminã䜿çšããŠã€ã³ããã¯ã¹ãäœæãã
PhpMiniAdminã§ã¯ãããŒãžã®äžéšã«å¯Ÿå¿ãããã£ãŒã«ããæ¿å ¥ããŠã次ã®ãªã¯ãšã¹ããå®è¡ããå¿ èŠããããŸãã
ALTER TABLE orders ADD INDEX customeridindex (customerid);
ã€ã³ããã¯ã¹ã®äœæåŸã«æ€çŽ¢ã¯ãšãªãå®è¡ããã«ã¯ãã³ã³ãã¥ãŒã¿ãŒã§0.0019ç§ããããŸãããããã¯113åé«éã§ãã
å šæ玢åŒã®è¿œå ãåæ§ã«è¡ãããŸãã ã€ã³ããã¯ã¹ã¯ãå®éã«æ¢ããŠããåã«åŸã£ãŠã³ã³ãã€ã«ããå¿ èŠããããŸãã
ALTER TABLE articles ADD FULLTEXT(title,author,articletext); SELECT * FROM articles WHERE MATCH(title,author,articletext) AGAINST ('mysql');
ããã¯ã¢ãããšã»ãã¥ãªãã£
ããŒãã«ã«å€æŽãå ããåã«ãããŒã¿ããŒã¹å šäœã®ããã¯ã¢ããã³ããŒãäœæããŸãã ãããè¡ãã«ã¯ã[ãšã¯ã¹ããŒã]ãã¿ã³ãã¯ãªãã¯ããŠPhpMyAdminããã³PhpMiniAdminã䜿çšããŸãã ããŒã¿ããŒã¹ã«é¡§å®¢ãªã©ã®éèŠãªæ å ±ãå«ãŸããŠããå Žåã¯ãããã¯ã¢ãããå®å šãªå Žæã«ä¿ç®¡ããŠãã ããã mysqldumpã³ãã³ãã䜿çšããŠãSSHçµç±ã§ããŒã¿ããŒã¹ãããã¯ã¢ããããããšãã§ããŸãã
mysqldump --user=myuser --password=mypassword --single-transaction --add-drop-table mydatabase > backup`date +%Y%e%d`.sql
åæ§ã®ã·ããªãªã¯ã次ã®ãããªã»ãã¥ãªãã£ãªã¹ã¯ããããããŸãã æ»æè ã«ããŒã¿ãžã®ç°¡åãªã¢ã¯ã»ã¹æ¹æ³ãæäŸããŸãã ãµãŒããŒç®¡çããŒã«ã«ãã£ãŠããçšåºŠä¿è·ãããŠããPhpMyAdminãšã¯ç°ãªããphpMiniAdminã¯çæéããŠã³ããŒãããŠå¿ããŠããŸãããšãããåäžã®ãã¡ã€ã«ã§ãã ãã¹ã¯ãŒãã§ã¢ã¯ã»ã¹ãä¿è·ãããã䜿çšåŸããã«åé€ããããšããå§ãããŸãã
ããŒãã«ãæé©åãã
MySQLããã³ãã®ä»ã®çš®é¡ã®ããŒã¿ããŒã¹ãœãããŠã§ã¢ã«ã¯ãæé©åããŒã«ãçµã¿èŸŒãŸããŠããŸãã ããŒãã«å ã®ããŒã¿ãé »ç¹ã«å€æŽãããå Žåã¯ãåæ§ã®ããŒã«ãå®æçã«äœ¿çšããŠãããŒã¿ããŒã¹ããŒãã«ã®ã¹ããŒã¹ãç¯çŽããå¹çãé«ããããšãã§ããŸãã ãã ãããã®ãããªæé ã«ã¯äžå®ã®æéïŒããŒãã«ã®ãµã€ãºã«å¿ããŠæ°ç§ããæ°å以äžïŒãããããä»ã®ã¯ãšãªããããã¯ããå¯èœæ§ããããããè² è·ãæå°ã®æéã«æé©åãè¡ãããšããå§ãããŸãã å¿ èŠãªæé©åã®é »åºŠã«é¢ããè«äºã¯ãããŸããŸãã ã
ïŒ ordersããŒãã«ã®ïŒæé©åæé ãéå§ããã«ã¯ã次ã®ã³ãã³ããå®è¡ããŸãã
OPTIMIZE TABLE orders;
100,000ã¬ã³ãŒãã®æé©åãããŠããªã泚æããŒãã«ã¯31.2 MBãå æãã SELECT * FROM泚æã®åœ¢åŒã®ã¯ãšãªã¯0.2676ç§ã§å®äºããŸããã æåã®æé©åã®åŸããµã€ãºã¯30.8 MBã«çž®å°ãããèŠæ±ã¯0.0595ç§ã§å®äºããŸããã
次ã®PHPé¢æ°ã¯ãããŒã¿ããŒã¹å ã®ãã¹ãŠã®ããŒãã«ã®æé©åãéå§ããŸãã
function OptimizeAllTables() { $tables = mysql_query ('SHOW TABLES'); //get all the tables while ($table = mysql_fetch_array ($tables)) mysql_query ('OPTIMIZE TABLE ' . $table[0]); //optimize them }
ãã®æ©èœãéå§ããåã«ãããŒã¿ããŒã¹ã«æ¥ç¶ããå¿ èŠããããŸããæè¿ã®ã»ãšãã©ã®ãµã€ãã¯ãããèªåçã«è¡ããŸãããå®å šãæãããã«ã察å¿ããã³ãŒãã瀺ããŸãã
mysql_connect (DB_HOST, DB_USER, DB_PASSWORD); mysql_select_db (DB_NAME); OptimizeAllTables();
ãã£ãã·ã¥ã䜿çšããŸã
ãã©ãŠã¶ã蚪åããWebããŒãžããã£ãã·ã¥ããããã«ãé »ç¹ã«å®è¡ãããããŒã¿ããŒã¹ã¯ãšãªã«ã€ã³ããã¯ã¹ãä»ããããšãã§ããŸããäžèšã®ãªã¯ãšã¹ããå®äºããã«ã¯0.0019ç§ããããŸãããã€ã³ããã¯ã¹ã䜿çšïŒ
SELECT * FROM orders WHERE customerid=2;
åããªã¯ãšã¹ããç¹°ãè¿ãå®è¡ããã«ã¯ã0.0004ç§ããããããŸãããMySQLã¯å®è¡çµæãèšæ¶ããŠãããã¯ãšãªãå®å šã«åå®è¡ããããšãªãåºåã§ããŸãã
ãã ããå€ãã®ãã¥ãŒã¹ãµã€ããããã°ã§ã¯ãåæ§ã®ã¯ãšãªã䜿çšããŠããå ¬éãæ¥ä»¥éã«ã®ã¿èšäºã衚瀺ãããããã«ããŸãã
SELECT * FROM posts WHERE publisheddate <= CURDATE(); SELECT * FROM articles WHERE publisheddate <= NOW();
ãã®ãããªãªã¯ãšã¹ãã¯ãã£ãã·ã¥ã§ããªãããããããã¯çŸåšã®æ¥æã«äŸåããŸãã100,000ã¬ã³ãŒãã®ããŒãã«ã§ãäžèšã®ããããã®ã¿ã€ãã®ã¯ãšãªãçŽ0.38ç§éã³ã³ãã¥ãŒã¿ã§å®è¡ãããŸãããã€ã³ããã¯ã¹ãªãã®åã
ãã®ãããªãªã¯ãšã¹ãããµã€ãã®åããŒãžã§æ¯åæ°çŸåå®è¡ãããå Žåããã£ãã·ã¥ããã ãã§çç£æ§ãå€§å¹ ã«åäžããŸããNOWãšCURDATEãå®éã®æéã«çœ®ãæããããšã§ãããšãã°æ¬¡ã®ããã«ãªã¯ãšã¹ããã匷å¶ãããŠãã£ãã·ã¥ã䜿çšã§ããŸãã
SELECT * FROM articles WHERE publisheddate <= '2011-01-17 17:00';
PHPã䜿çšããŠãæéééã5åçšåºŠã§ããããšã確èªã§ããŸãã
$time = time(); $currenttime = date ('Ymd H:i', $time - ($time % 300)); mysql_query (âSELECT * FROM articles WHERE publisheddate <= '$currenttime'â);
åŒïŒ 300ã¯ãæéãæãè¿ã300ç§ïŒ5åïŒã«äžžããŸãã
MySQLã«ã¯ãRANDãªã©ã®ä»ã®ãã£ãã·ã¥äžå¯é¢æ°ããããŸãã
ãããŠããã£ãã·ã¥ã¯æé·ããŠããŸã...
ãã£ãã·ã¥ãããããŒã¿ã®éãå¢ãããšãWebãµã€ãã®é床ãäœäžããŸãããµã€ãã«æçš¿ãããŒãžãã«ããŽãªã補åãèšäºããã®ä»ã®èŠçŽ ãå¢ããã»ã©ãã¯ãšãªã®é¢é£æ§ãé«ãŸããŸããäŸãèŠãŠã¿ãŸãããïŒ
SELECT * FROM articles WHERE publisheddate <= '2011-01-17 17:00' AND categoryid=12;
ãµã€ãã«500ã®ã«ããŽãªãããå Žåããã®ãããªãªã¯ãšã¹ãã¯ãã£ãã·ã¥ãããçµæã¯ããªç§ãè¿ããŸãããããã1000åã®åžžæ衚瀺ãããã«ããŽãªãããå Žåã¯ã©ãã§ããããïŒãããã¯äºãã«ãã£ãã·ã¥ããæŒãåºãããã¯ããã«é ãå®è¡ãããŸãããã®å Žåããã£ãã·ã¥ã®ãµã€ãºãå¢ãããšåœ¹ç«ã€å ŽåããããŸãããã ãããã£ãã·ã¥ã«ããå€ãã®ã¡ã¢ãªãå²ãåœãŠããšãä»ã®ã¿ã¹ã¯ã«æªåœ±é¿ãäžããå¯èœæ§ãããããã泚æããŠãã ããããµãŒããŒå€æ°ãå€æŽããããšã«ããããã£ãã·ã¥å¹çãæå¹ã«ããŠæ¹åããããã®å€ãã®ãã³ããèŠã€ããããšãã§ããŸãã
ãã£ãã·ã³ã°ãç¡åãªå Žå
ããŒãã«ãå€æŽãããå Žåããã£ãã·ã¥ã¯ç¡åã«ãªããŸããããŒãã«ããè¡ãæ¿å ¥ãæŽæ°ãåé€ãããšããã®ããŒãã«ã«é¢é£ãããã¹ãŠã®ã¯ãšãªããã£ãã·ã¥ããåé€ãããŸãããããã£ãŠãèšäºãèŠããã³ã«ããŒãã«ãèšäºããæŽæ°ãããå ŽåïŒããšãã°ããã®ããŒãã«ã«ãã¥ãŒã«ãŠã³ã¿ãŒãæã€ãã£ãŒã«ããããå ŽåïŒãäžèšã®æ¹åã¯åœ¹ã«ç«ããªãå¯èœæ§ããããŸãã
ãã®ãããªå Žåãã¢ããªã±ãŒã·ã§ã³ã¬ãã«ã§ãã£ãã·ã¥ãå®è£ ããããŒã«ïŒMemcachedãªã©ïŒãåŠç¿ããå¿ èŠããããŸãããŸããç¬èªã®ãã£ãã·ã³ã°ã·ã¹ãã ã®äœæã«é¢ãã詳现ã«ã€ããŠã¯ã次ã®ã»ã¯ã·ã§ã³ããèªã¿ãã ããããããã®ãªãã·ã§ã³ã¯ã©ã¡ããã説æãããããã¯ããã«å€§ããªãœãããŠã§ã¢å€æŽãå¿ èŠãšããŸãã
ç¬èªã®ãã£ãã·ã¥
ç¹ã«éãããŒã¿ããŒã¹ã¯ãšãªã®å®äºã«æéãããããããŒã¿ãé »ç¹ã«å€æŽãããªãå Žåã¯ãçµæãèªåã§ãã£ãã·ã¥ã§ããŸãã
æ€çŽ¢ã¯ãšãªããã¥ãŒããæ°ã«å ¥ããžã®è¿œå ãå人ãžã®éä¿¡ãèæ ®ã«å ¥ããåŒã䜿çšããŠãå é±ãµã€ãã§20ã®äººæ°ã®ããæçš¿ã衚瀺ãããšããŸãããããŠãã¡ã€ã³ããŒãžã«ãã®ãªã¹ããç®æ¡æžããªã¹ããšããŠè¡šç€ºããããšããŸãã
ããšãã°ãPHPã䜿çšããæãç°¡åãªæ¹æ³ã¯ã1æéãŸãã¯1æ¥1åããŒã¿ããŒã¹ã«ã¯ãšãªãå®è¡ããçµæãå¥ã®ãã¡ã€ã«ã«ä¿åããããšã§ãããã®ãã¡ã€ã«ã¯ãµã€ãããŒãžã«æ¥ç¶ãããŸãã
ãªã¹ããã¡ã€ã«ãçæããPHPã³ãŒããèšè¿°ããåŸãããã€ãã®æ¹æ³ã䜿çšããŠã¹ã±ãžã¥ãŒã«ã«åŸã£ãŠå®è¡ã§ããŸãããµãŒããŒã¹ã±ãžã¥ãŒã©ïŒPlesk 8ïŒãµãŒããŒâã¹ã±ãžã¥ãŒã«ãããã¿ã¹ã¯ïŒã䜿çšããŠããã®ã¹ã¯ãªããã次ã®ããã«1æéããšã«å®è¡ã§ããŸãã
wget -O /dev/null -q http://www.mywebsite.co.uk/runhourly.php
ãŸãã¯ãåãPHPã䜿çšããŠãã¡ã€ã«äœææéã確èªã§ããŸãããã¡ã€ã«ãå°ãªããšã1æéåã«äœæãããå Žåããªã¯ãšã¹ããå®è¡ããŸãããã®å Žåã®3600ã¯ã1æéãããã®ç§æ°ã§ãã
$filestat = stat ('includes/complicatedfile.html'); //look up information about the file if ($filestat['mtime'] < time()-3600) RecreateComplicatedIncludeFile(); //over 1 hour readfile ('includes/complicatedfile.html'); //include the file into the page
äžèšã®äŸã顧客ã¯ãã®è£œåã§ä»ã«äœãè³Œå ¥ããŸãã...ãã«æ»ããšãäžè¬ã«æ°ããåãŸãã¯ããŒãã«ã«ããŒã¿ããã£ãã·ã¥ããããšãã§ããŸããé±ã«äžåºŠãå補åã«å¯ŸããŠè€éãªã¯ãšãªã®å€§èŠæš¡ãªã»ãããå®è¡ããŠãè³Œå ¥ãã補åã決å®ã§ããŸãã
ãã®åŸãçµæã®è£œåèå¥åããã³ã³ãã§åºåãããèŠçŽ ã®ã»ãããšããŠæ°ããåã«ä¿åã§ããŸããå°æ¥ãid = 12ã®è£œåãšäžç·ã«è³Œå ¥ãããååã®ãªã¹ããååŸããã«ã¯ã次ã®éæé·ãå®è¡ããå¿ èŠããããŸãã
SELECT * FROM products WHERE FIND_IN_SET(12,otherproductids);
JOINã䜿çšããŠã¯ãšãªã®æ°ãæžãã
ãµã€ãã®ããããã®ã»ã¯ã·ã§ã³ïŒç®¡çã»ã¯ã·ã§ã³ãªã©ïŒã«ã泚æã®ãããŠãŒã¶ãŒã®ãªã¹ãã衚瀺ãããŸãã
ãã®å Žåã以äžã®ãããªã¯ãšãªã䜿çšãããŸãïŒæ³šæãå®äºããããšãæå³ããå€ã«ããéžæã®ããïŒïŒ
SELECT * FROM orders WHERE status>1;
ãããŠã泚æããšã«ããããçºè¡ããã¯ã©ã€ã¢ã³ããèŠã€ããå¿ èŠããããŸãã
SELECT * FROM customers WHERE id=1; SELECT * FROM customers WHERE id=2; SELECT * FROM customers WHERE id=3; etc
100件ã®æ³šæã«é¢ããæ å ±ãããã«ããŒãžã«è¡šç€ºãããå Žåã101件ã®ãªã¯ãšã¹ããè¡ãå¿ èŠããããŸããããã«ãå¥ã®ããŒãã«ããã®é éå äœæã«é¢ããæ å ±ããã¹ãŠã®æ³šæã®ç·ã³ã¹ããããŒãžäœæé床ãäœäžãããäœäžãããªã©ã®æ å ±ãå¿ èŠãªå Žåã¯ãJOINãä»ããŠãªã¯ãšã¹ããçµã¿åãããããšã«ããããã¹ãŠãã¯ããã«é«éã«å®è¡ã§ããŸãã以äžã¯ãäžèšã®ã¯ãšãªãçµã¿åãããäŸã§ãã
SELECT * FROM orders INNER JOIN customers ON orders.customerid = customers.id WHERE orders.status>=1;
ãããã®ãªã¯ãšã¹ããèšè¿°ããå¥ã®æ¹æ³ããããŸãããJOINã䜿çšããŸããã
SELECT * FROM orders, customers WHERE orders.customerid = customers.id AND orders.status>=1;
JOINã䜿çšããããã®ãªã¯ãšã¹ãã翻蚳ããã®ã¯é£ããå ŽåããããŸãã PHPã³ãŒããå€æŽããå¿ èŠããããŸãããããããé ããããŒãžã§äœåãã®ãªã¯ãšã¹ããå®è¡ãããå Žåã説æãããŠããæ¹æ³ã«æ³šæãæãå¿ èŠããããããããŸããã詳现ã«ã€ããŠã¯ããŠã£ãããã£ã¢ãåç §ããŠãã ãããããã«ã¯JOINã®è©³çŽ°ãèšèŒãããŠããŸãã JOINã§äœ¿çšãããåïŒãã®äŸã§ã¯customeridïŒã«ã€ã³ããã¯ã¹ãä»ããå¿ èŠããããŸãã
ãŸããMySQLã«ã¯ãšãªã®å®è¡æ¹æ³ãã説æãããããã«äŸé Œããããšãã§ããŸãããã®çµæãã¯ãšãªã®å®è¡æã«ã©ã®ããŒãã«ãã©ã®ããã«äœ¿çšãããããããããäœããæé©åã§ããŸãã以äžã®ã¹ã¯ãªãŒã³ã·ã§ããã¯ãEXPLAINã䜿çšããŠWordPressã§è€éãªã¯ãšãªã®1ã€ãå®è¡ããçµæã瀺ããŠããŸãã
EXPLAINã䜿çšããŠãMySQLãè€éãªã¯ãšãªããèªèãããæ¹æ³ãåŠç¿ããŸã
ã¹ã¯ãªãŒã³ã·ã§ããã«ã¯ã䜿çšãããŠããããŒãã«ãšã€ã³ããã¯ã¹ãJOINã®ã¿ã€ããåæãããè¡ã®æ°ããã®ä»ã®æ å ±ã衚瀺ãããŸããMySQLã®å ¬åŒWebãµã€ãã§ã¯ãEXPLAINã®èª¬æã«ã€ããŠèª¬æãããã®æ å ±ã䜿çšããŠã¯ãšãªãæé©åããæ¹æ³ã«ã€ããŠå°ã説æããŠããŸãïŒããšãã°ãã€ã³ããã¯ã¹ãè¿œå ãããªã©ïŒã
ããŒã
æåŸã«ãã顧客ã¯ãã®è£œåã§ä»ã«äœãè³Œå ¥ããŸãã...ãã®äŸã«æ»ãããããåçŽåã§ããŸããããšãã°ããFeatured Productsããšããååã«å€æŽããåãã«ããŽãªã®ä»ã®è£œåãããã€ã衚瀺ããããæåã§æå®ããŸãã
ãããã«
ãã®èšäºã§ã¯ãããŒã¿ããŒã¹ã®ããã©ãŒãã³ã¹ãåçŽãªãã®ããããªãè€éãªãã®ã«æ¹åããããã€ãã®æ¹æ³ã瀺ããŸããããèšèšãããã»ãšãã©ã®ãµã€ãã«ã¯ããã§ã«ãã®ãããªã¡ãœãããå«ãŸããŠããã¯ãã§ãïŒJOINãšã€ã³ããã¯ã¹ã䜿çšïŒã
説æããããã€ãã®æ¹æ³ïŒé床枬å®ãã€ã³ããã¯ã¹ä»ããæé©åããã£ãã·ã¥ãªã©ïŒã䜿çšããããšã®å¹çãšä¿¡é Œæ§ã«ã€ããŠã¯å€ãã®è°è«ããããããæçµçãªæ±ºå®ã¯ããªã次第ã§ãããããã«ãããä»èããã¹ãéžæè¢ããããŸãã
æ°ãæãŸãã¯æ°å¹Žã®éåžžã®æäœåŸã«ãµã€ãã®åäœãé ããªã£ãå Žåãçç±ãèŠã€ããããã«äœããå§ããå¿ èŠããããŸãã