(主ã¨ãã¦ã¡ã¢ãªé¢é£ã¨ãã®)å°æ
ãã¨â¦ã¡ããã¨æ°ä»ãããããå°æã¢ããªãã¦å°æå種ã
ãã¡ã
ã¶ã£ã¡ãããå¥å¦ãªã©ã¤ãã©ãªãOSSã®é¡ã®ãã ããªã¨ã©ã¼ææ¢æ¼ç®åããæè¿éªéã§ãã¾ãã¾ãã(ã¨ãããMWã«ãããã®ã§â¦æ¶ããªãã¨ãã)ã
ã ã£ã¦ãåºåã¯ãã¨ã§ error_reporting( http://d.hatena.ne.jp/gallu/20090423/p1 )ã§å¶å¾¡ãããããã£ããï¼
ã£ã¤ããã§ãããã
http://jp.php.net/manual/ja/scream.examples-simple.php
ini_set('scream.enabled', false);
ãã¨ã©ã¼æå¶æ¼ç®åã®ç¡å¹åãã¨ãããã©çãä¸ã¯ãªãã£ã«ã«ããããªæãã®ãã®ãããã¾ãï½
ä¸æã«ä½¿ãã¾ããããç¹ã«é¢åãªç¾å ´ã§ orz
ã«ã
gc_collect_cyclesã
ãã¹ã¦ã®æ¢åã¬ãã¼ã¸ãµã¤ã¯ã«ãå¼·å¶çã«åéããã£ã¦äºã§â¦å±ãªããã§ãããã便å©ããã§ãããã
â¦ã ããå®é¨ããã²ã¨ããã¾ããï¼ï½
# (PHP 5 >= 5.3.0)ãã ãããªãâ¦
ããã
memory_get_peak_usage ï¼ memory_get_usageã
ãããããPHPåãé£ãåãã¦ããã¡ã¢ãªéãåºåãããã§ãã
åè
ããæ大å¤ããå¾è
ããç¾å¨å¤ãã示ãã¾ãã
memory_get_peak_usageã«é¢ãã¦ã¯ãæ£ç´å¼æ°ãfalse(çç¥å¤)ã«ããæå³ãããããã§ãããªã®ã§ãå¯è½ãªéãtrueãã
memory_get_usageã®å ´åãé¢æ°ã®ãã¥ã¼ãã³ã°ããªãfalseãããç¨åº¦ããããã ç¾å®åé¡ã¨ãã¦ã·ã¹ãã ã«å¯¾ãã¦ãªã«ãããå½±é¿ãåã¼ãã®ã¯çµå±ãä»ãã¬ã¡ã¦ãã¡ã¢ãªéããªã®ã§ããã£ã±ãtrueã®ã»ãããããã¹ãããã ã¨æãã
ã§â¦ã©ãããããã©ã§256k(å¤åã³ã³ãã¤ã«ãªãã·ã§ã³ãã®ä»ã§å¤åããã¨äºæ³ãããã¡ããã®ç°å¢ã®å ´åã§ã)ã¯çµ¶å¯¾ç¢ºä¿ããã¿ããã
ãªã«ã
<?php var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) );
ã®çµæã
int(51616)
int(262144)
int(47292)
int(262144)
ã§ãããã
é¢ç½ãã®ããããã¡ãã£ã¨è² è·ããããæ(å°ãªãã¨ã以åã¯ãPHPã®ã¬ãã³ã¬ã大åè ã£ã¦ãã®ã§â¦ã·ã¹ãã èªä½ã«å§ããããå ´åã«åãããã«ãªããã¯ä¸æ)ã
<?php require_once('/opt/www/mw.conf'); var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n"; $s = 'aaaa( aãï¼ä¸æå )'; var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n"; $s = ''; unset($s); var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n"; $s = file_get_contents( ã¦ãã¨ããªãµã¤ãã®URI ); var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n"; $s = ''; var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n"; unset($s); var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n"; $a = array(); for($i = 0; $i < 10000; $i ++) { $a[] = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; } var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n"; $a = array(); var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n"; unset($a); var_dump( memory_get_peak_usage() ); var_dump( memory_get_peak_usage(true) ); var_dump( memory_get_usage() ); var_dump( memory_get_usage(true) ); print "-----------\n";
ã³ããé£æãªã®ã¯æ°ã«ãããªããè²ã
試ããªããããã¾ã§ãµããããã ï½
ãã§ãããã®çµæã
int(105488)
int(262144)
int(71760)
int(262144)
- -
int(105488)
int(262144)
int(81844)
int(262144)
- -
int(105488)
int(262144)
int(71760)
int(262144)
- -
int(107188)
int(262144)
int(89412)
int(262144)
- -
int(107188)
int(262144)
int(73272)
int(262144)
- -
int(107188)
int(262144)
int(73184)
int(262144)
- -
int(1940240)
int(2097152)
int(1939004)
int(2097152)
- -
int(1940312)
int(2097152)
int(73416)
int(524288)
- -
int(1940312)
int(2097152)
int(73256)
int(524288)
- -
ã¨ããããããªãã¡ã¬ã³ã¹ã«ã¦ã³ã¿åããªãunsetãªãããããªãã«æå¹ã«åãã¦ããäºã確èªã§ãã¾ãã
ã¨ã¯ããåºæ¬ã¡ã¢ãªã¯ããããã¯åä½ã§åãåºãã¦ããããããªã®ã§ãããã¾ããã¾ããªãã«ããã«ããã©ããããæå³ãããã®ãã¯ããããã®å®é¨ã¨æ¤è¨¼ãå¾
ã¤å¿
è¦ãããã¾ãï½
ã¾ããè²ã
ã¨ä½¿ããã¨ããã§ã¯ãªãã§ããããï¼
ãã¾ãã
ãã¨â¦ããã¡ãããæ³å®ãã¦ãã使ãæ¹ã
ï¼ï¼ããªããï¼åºç»(ã¯ã©ã¹ã¨ãé¢æ°ã¨ã)ã§å¦ã«ã¡ã¢ãªé£ãåãã¦ãæ°ãããã
memory_get_usageããå¼æ°falseã¨trueã®åæ¹ã§åã£ã¦ãã ããã
ãã®è¾ºããã®ã³ã°ããã¨ãåæã®å½¹ã«ç«ã¡ã¾ãå¤åã
ï¼ï¼è½ã¡ã orz
ããã°ã©ã ã®ã©ã¹ãã®ã»ãã§memory_get_peak_usageãtrueã§å©ãã¦ãã ããã
ã©ããããè´
æ²¢ã§æ½¤æ²¢ã§ã ããªã¡ã¢ãªä½¿ãããã¦ããã®ããä¸æã§ãããã¾ã orz
ãã¦â¦Weponã®ãã®ã³ã°æ©è½ã« memory_get_peak_usage ãããã¯ã¶ã¡è¾¼ãã§ããããªã