PHP ÇÁ·Î±×·¥À» µð¹ö±ë ÇÏ·Á¸é ´ÙÀ½ÀÇ ÇÔ¼ö¸¦ °¡Áö´Â "debug2.inc"À̶õ ÈÀÏÀ» ¸¸µé¾î¶ó :
<?php /* ÀÌÁßÀ¸·Î ¼±¾ðµÇ´Â °ÍÀ» ¹æÁöÇϱâ À§ÇÑ º¯¼öÁ¤ÀÇ */ if (!defined("_DEBUG2_DEFINED_")) { define("_DEBUG2_DEFINED_", 1 ); } else return; // ¸¸¾à ÀÌÈÀÏÀÌ include µÆ´Ù¸é ¸®ÅÏ # file name : debug2.inc # PHP ¼Ò½º Äڵ带 µð¹ö±ëÇϱâ À§ÇÑ ÇÔ¼öµé #***************************************************************** # Copyright policy is GNU/GPL but additional request is # that you include author's name and email on all copies # Author : Al Dev Email: alavoor@yahoo.com #***************************************************************** # Usage of this functions - # In your source code put something like - # debug2_(__FILE__, __LINE__, "f_somevariable", $f_somevariable); # And this will generate output in debug.out file. //function debug2_($fname, $lname, $debug_var, $debug_value=0) {} // Give read, exec for all on directory /debug2_logs // chmod a+rwx /debug2_logs // But here you need to open the file in append mode. $fp_debug2 = fopen("/debug2_logs/debug.out", "a"); if ($fp_debug2 == false) { print "<b>File open failed - global.var.inc<b>"; exit; } function debug2_($fname, $lname, $debug_var, $debug_value=0) { global $fp_debug2; //print "<br> debug_value is : $debug_value <br>"; if (!$debug_value) { fwrite($fp_debug2, "\n ". $fname ." ". $lname .": $debug_var"); } else { fwrite($fp_debug2, "\n ". $fname . " ". $lname .": $debug_var = $debug_value"); } //print "<br> f_cookie is : $f_cookie <br>"; } // In your first page, which is generally index.php3 // truncate the debug2_logs file in beginning of code function init_debug_file() { global $fp_debug2; $fp_debug2 = fopen("/debug2_logs/debug.out", "w"); if ($fp_debug2 == false) { print "<b>File open failed - global.var.inc<b>"; exit; } system("chmod a+rwx /debug2_logs/debug.out"); } ?>
º¸Åë index.php3·Î µÇ´Â ½ÃÀÛÆäÀÌÁöÀÇ PHP ¼Ò½ºÄڵ忡 ´ÙÀ½À» Áý¾î³Ö¾î¶ó.
<?php include ("debug2.inc"); init_debug_file(); // ´Ù¸¥ ¸í·ÉÀº ¿©±â¿¡..... // ........... ?>
µð¹ö±ë °ªÀ» ¾ò±âÀ§ÇØ PHP ¼Ò½ºÄÚµå ÆÄÀÏ¿¡ debug2_() ¶õ È£ÃâÀ» ¾Æ·¡¿Í °°ÀÌ ³Ö¾î¶ó
<?php include ("debug2.inc"); debug2_(__FILE__, __LINE__, "f_somevariable", $f_somevariable); function aa() { $aa = 8; debug2_(__FILE__, __LINE__, "aa", $aa); } ?>
PHP ÇÁ·Î±×·¥À» ½ÇÇàÇÏ°Ô µÇ¸é, °á°ú°¡ debug.out À̶õ ÈÀÏ¿¡ ÆÄÀÏÀ̸§, ¶óÀιøÈ£, º¯¼ö¸í °ú º¯¼ö°ªÀÌ ³ªÅ¸³´Ù.
ÀϹøÀûÀ¸·Î debug2_()¸¦ »ç¿ëÇ϶ó. ÇÁ·Î±×·¥¿¡¼ debug2_()ÀÇ È£ÃâÀº ÃÖÁ¾°á°ú Äڵ忡 ¾î¶°ÇÑ ¿µÇâµµ ÁÖÁö¾ÊÀ¸¸ç ½ÇÇà¿¡µµ ¾Æ¹«·± ¿µÇâÀ» ÁÖÁö¾Ê´Â´Ù. ¿Ö³ÄÇÏ¸é ¾Æ·¡¿¡ ±â¼úÇÑ°Í °°ÀÌ ÇÊÅ͸µ µÇ±â ¶§¹®ÀÌ´Ù. debug2_()¸¦ ŸÀÌÇÎÇÏ´Â ½Ã°£À» ÁÙÀ̱â À§ÇØ º¹»ç(copy)¿Í ºÙ¿©³Ö±â(paste)¸¦ »ç¿ëÇÒ¼ö ÀÖ´Ù. ¶ÇÇÑ Vi ¿¡µðÅÍÀÇ 'yank to buffer' ±â´ÉÀ» ÀÌ¿ëÇؼ º¹»çÇ϶ó.
°³¹ßÀÌ ¿Ï·áµÇ¸é Å×½ºÆ®ÇÏ°í ¼¹ö¿¡ ¿Ã¸° Áغñ°¡ µÆÀ¸¸é ¼Ò½ºÄڵ忡¼ debug2_ È£ÃâÀ» ÇÊÅ͸µ Ç϶ó. À¯´Ð½º ÇÁ·ÒÇÁÆ®¿¡¼ -
bash$ mkdir production bash$ grep -v debug2_ filea.php3 > production/filea.php3
bash$ mkdir production bash$ ls *.php3 | while read ans do grep -v debug2_ $ans > production/$ans done