PHPãªãã§ã¯ã®
[PHP-users 6012] Re: PHP デザインパタン
ãã®æ稿ããã ãã¶æéãçµã£ã¦ããã ãã©ãPHPãªãã§ã¯ã®ãã¿ã¼ã³ã£ã¦ããã®ããªï¼
å¤æ°ã§ã¯ãªãå¤ã«åããããã¨ãå©ç¨ãããããªãã¿ã¼ã³ããã
mixedãåãåã£ã¦ããããã®æ´¾çã¯ã©ã¹ã¨ããããã©ã¤ãã¯ã©ã¹ã§åãã¨ã«éãå®è£
ãããã¨ãï¼
ã§ãä»ã®è¨èªã ã¨ãªã¼ãã¼ãã¼ãã§åºæ¥ããã¨ããªã¼ãã¼ãã¼ããã¿ã¼ã³ï¼ï¼ï¼ã«ããªãã¨ãããªãã¨ãï¼ãã¼ãã
ãµãã¿ã¤ãº
åãåå¿ãé
ããã©ã
高木浩光@自宅の日記 - プログラミング解説書籍の脆弱性をどうするか, 「サニタイズ言うなキャンペーン」とは何か, ASPとかJSPとかPHPとかERBとか、逆だ..
æè¿ã®ããã°ã©ã å ¥éæ¸ã¯ãæåå解ææ©æ§ãããã¨ããèãæ¹ããªãã®ããªãæ¸ãã¦ã人ãããããæèããã¾ãç¡ãã®ãããããªãã
ç§ãåãã¦ããã°ã©ã ãæ¸ããã®ã¯Perlã®æ²ç¤ºæ¿ã ã£ãããã«æããï¼Cè¨èªã®å
¥éæ¸ã¯æ°åè¨ç®ã¨ãã«ã¬ã³ãã¼è¡¨ç¤ºã¨ãé¢ç½ããªãä¾ãããªãã£ãï¼
åãã«HTTPããããåºåãã¦ããªã¯ã¨ã¹ãã&ã¨=ã§åºåã£ã¦å¤æ°ã«å
¥ããåºåæã«ãã¾ãã¾ãæ£è¦è¡¨ç¾ã使ã£ã¦ < ã < ã«å¤æãã¦ãã£ããã¨ãã
ãã®ä¸ã§ä¾ãã°ãã©ã³ãã¿ã°ã使ããããªããã©ã³ãã¿ã°ã ã許å¯ããã
ãããçããã§ãã¯ã ã¨å±æ§ã使ã£ã¦ããæªæ¯ï¼ï¼ï¼ãããããæ£ç¢ºã«ãã¼ã¹ããªããã°ãªããªãã£ãã¨æãã
ç¦æ¢ããã¿ã°ã ãè¨å®ããã¨ããããä¾ãã°
<script>
ã®æååãåç´ã«ãç¦æ¢ãã¦ããããã«
< script >
ã¨ããããã¡ããã
ãã¡ã¤ã«ã«ä¿åããã¨ããå®æã«ã¿ãåºåãã«ãã¦ãã¨ãã¿ããã³ããã§å
¥åããã¦ãã°ã£ããã
ãããªããã§æååã解æãã¦æ£ããå¦çãããã¨ãããã¨ã¯æ®éã ã£ãããã§ã
åºåãæåï¼ãã¼ã¯ã³ï¼ç¹å¥ãªæå³ãããæåï¼ã«ã¤ãã¦ã¯å
¥éã®æç¹ã§è§£èª¬ããã¦ããã
ãããPHPã«ãªãã¨ãªã¯ã¨ã¹ãã$_GETã§ç°¡åã«åãåããããDBãç°¡åã«ä½¿ãããã§ããããæã«æèãåãã«ããã®ããã
DBã«ãã¦ãã·ã³ã°ã«ã¯ã©ã¼ãã¼ã·ã§ã³ããã¼ã¿ã¨ãã¦è¨é²ã§ããã¹ãã ãããã¡ã¤ã«åã«ãã¦ã../ãè¨é²ã§ããã¹ãã ã
ä¾ãã°ã¢ãããã¼ãã§ãã¡ã¤ã«åã../ã¨ãã¦ã¢ãããã¦ããã¿ã¤ãã«ä¸è¦§ã§../ã表示ã§ãã¦å
容ãè¦ããæ¹ãæ®éã ã¨ã¾ãèãããã¢ããªã±ã¼ã·ã§ã³ä¸ã®ãã¡ã¤ã«åã¨å®éã®ãã¹ã¯å¥åé¡ãå®éã®ãã¹ã¨åä¸ã«ããã®ã¯æãæãããã ã¨èããã°ããã ã®æååã¨å®éã®ãã¹ã®æ±ãæ¹ã«ã¤ãã¦èªç¶ã¨æèããã
æï¼5ï¼6å¹´åï¼ï¼ã®å ¥éæ¸ãèªãã ãèªç¶ã¨ããããèãæ¹ã«ãªã£ãæ°ããããã ãã©ããä»ã¯ç¡çãªã®ãã便å©ã§ç°¡åã«ããã°ã©ã ãæ¸ããããã«ãªã£ã¦ãé ã追ãã¤ãã¦ãããªããããããµãã¿ã¤ãºã¨ãå·ãè¾¼ã¿ãããåã ãä»ã®æ¹ãåä»ãã
ã«ã¼ãã«ã½ã¼ã¹ã®ãã¹æ¢ç´¢é¨åãè¦ã¦ãã¨Cè¨èªã§ä¸æåä¸æå解æãã¦ããã ãã©ãããããé¨åãå®éã«è¦ããæ å ±ç³»ã®ææ¥ã§ç¿ã£ãããã¦ããã¨ã ãã¶éã£ã¦ãããã ãããªã
èå¼±æ§
åã®è¨äºã®ãªã³ã¯ã¯
ããã°ã©ãã³ã°è§£èª¬æ¸ç±ã®èå¼±æ§ãã©ãããã
ã¨ããããèå¼±æ§ã¨ããåèªããã¾ã好ããããªãã
ã©ããã«ãã°ã¨ããè¨èã«ã¤ãã¦ãããããèªç¶çºçãããããªå°è±¡ãä¸ãããããã¹ã¨è¨ãã¹ãï¼ãã°ãçºçããããããªãã¦ç´ç²ã«ãã¹ããã¦ããã ãã ï¼ãã¿ãããªæç« ããã£ããã©ããã¨åãã
ãã®ä¸çå
¨ä½ãå¿
ç¶çã«æ±ãè¾¼ãã§ããåé¡ï¼ã¾ãããã¯ããã§æ£ãããã ãããã©ï¼ã®ããã«æãã¦ãã¾ãã
èå¼±æ§ãå
ããåå¨ãã¦ãããããããªãã¦ãèå¼±ãªã·ã¹ãã ãä½ãè¾¼ãã ã®ã ã
ITç¨èªè¾å
¸ã«ããã¨ãã·ã¹ãã ä¸ã®æ¬ é¥ãä»æ§ä¸ã®åé¡ã®ãã¨ãããã
è¦ããã«ãããã°ã©ãã³ã°è§£èª¬æ¸ç±ã®æ¬ é¥ãã®ãã¨ã
å®ç§ãªãã®ãä½ãã£ã¦ããã®ã¯é£ããããå½¹ç«ã£ã¦ããé¨åãå¤ãããæãããè¨ã£ã¦ããã®ããªã
æ¥æ¬èªã®ææ§ãã¯æå¦çã«ã¯ãããã ãããã©ãããããåéã ã¨èãããã¨ãå¤ããªã£ã¦å¤§å¤ã ã
ãµã¨æãç«ã£ã¦memcacheãå ¥ãã
ã¾ãã¯memcached
apt-get install memcached
pecl install ã³ãã³ãã¯ãconfigureãªãã·ã§ã³ãå¤ããããªãã®ããªï¼ç§ã®éçºç°å¢ã¯PHP4ã¨PHP5ãå
±å*1ãã¦ããã®ã§è¿½å ã¢ã¸ã¥ã¼ã«ã®ã¤ã³ã¹ãã¼ã«ãç°¡åã«ãããªãã
æ¢ãã¦ãè¦ã¤ãããªãã£ããã½ã¼ã¹ã追ã£ã¦ãéãå¤ããã¦æ«æã»ã»ã²ã¨ã¤ã®é¢æ°ãé·ããã追ãã«ãããéãã¯ã©ã¹ã§åãã¡ã½ããã使ã£ã¦ãããgrepãã¥ããã»ã»ã
ã§ãä»æ¹ãªã
pecl download memcache tar xvzf memcache-2.1.0.tgz cd memcache-2.1.0 phpize5.1 ./configure --with-php-config=php-config5.1 make su make install
ã¨ããã
/etc/php5.1/cgi/conf.d/ ã«ãã¡ã¤ã«ãä½ã£ã¦ï¼/etc/php5.1/conf.d/ãããªã³ã¯ããæ¹ãè¯ãããï¼phpinfoã§ç¢ºèªã
ããã¾ã§ãã£ã¦æ°ä»ãããã©ããªã½ã¼ã¹åã¯ä¿åã§ããªãã®ãã»ã»ã»ãããããã ã
memcacheã®å¶é
きのうの memcached ネタ - にぽたん研究所
è²ã
æ¤ç´¢ãã¦ãperlã®ã³ã¼ããPHPã«æ¸ãç´ãã¦èªåã§å®è¡ãã¦ã¿ã¦ããã£ã¨ç解ããorz
æååã¯
$str = str_repeat('.', $size);
ã§ä½ã£ã¦ãã£ã¦ã¿ããã ãã©ãããã©ã«ãã®è¨å®ãããªããªãã¡ã¢ãªã使ãåããªãã
段ã
ä¸ãã¦ãã£ããé·ãã1048538ã¾ã§ããåãä»ããªãã£ããããã®ä¸éå端ãªæ°åã¯1MB-αï¼
ããã§70åç¹°ãè¿ãã¦ã¿ãã
<?php $size = 1; $count = 10; if (isset($_SERVER['argv'][1])){ $size = $_SERVER['argv'][1]; } if (isset($_SERVER['argv'][2])){ $count = $_SERVER['argv'][2]; } $m = new Memcache(); $m->connect('localhost', 11211) or die("connect error\n"); $str = str_repeat('.', $size); for ($i = 0; $i <= $count; $i++){ $m->delete($i); $m->set($i, $str) or print "set error\n"; echo "$i: " . strlen($m->get($i)) . "\n"; } sleep(1); for ($i = 0; $i <= $count; $i++){ echo "$i: " . strlen($m->get($i)) . "\n"; } ?>
ãããªã³ã¼ãã
flush()ããã£ã¦ããã¡ã
ãã¨flush()ã§æ°ä»ãããã©ãflush()å¾ã¯ããã«ãã£ãã·ã¥ãç»é²ã§ããªãã£ã½ããæ°ããç»é²ããããã¼ã¿ã¾ã§æ¶å»å¯¾è±¡ã«ãªã£ã¦ããããªåãã
usleep(100000)ãããããã使ããã
# ãã£ãã·ã¥ãµã¤ãºããã¼ã¿ã®æ°ã«ãã£ã¦å¤ãããããããªããããã®é¢æ°ã¯ä½¿ããªãæ¹ãå®å
¨ã