递归函数导致内存泄漏

时间:2019-10-16 10:54:37

标签: php sql

我刚开始使用php,并编写了以下函数来组织一个简单的注释线程。

function get_reply_comment($conn, $parentId, $marginleft)
{
  echo memory_get_usage();
 $sql = "SELECT * FROM tbl_comment WHERE parent_comment_id = '".$parentId."'";
 $result = mysqli_query($conn, $sql);
 $output = '';

 if($parentId == 0)
 {
  $marginleft = 0;
 }
 else
 {
  $marginleft = $marginleft + 48;
 }

while($row = mysqli_fetch_assoc($result))
{
 $output .= Stuff
  $output .= get_reply_comment($conn, $row["comment_id"], $marginleft);
 }
 return $output;
}

我一直在大量使用内存。我以为结果一次被称为一个,所以泄漏从哪里来?

0 个答案:

没有答案
相关问题