-3
我是新手。我有这段代码需要你的帮助来检查它是否会导致内存泄漏?这个代码的想法是检查status.txt文件是否为空,然后它的内容会显示在网页中,如果这个文件不是空的,它也检查readmore.txt文件,它会有一个指向文件的超链接。 下面是代码,请帮忙此PHP代码是否导致内存泄漏?
$statusfile = "status.txt";
$handle = fopen($statusfile, "r");
$string = '';
while (!feof($handle)) { $string .= fgets($handle); }
fclose($handle);
$readmore_file_path = 'readmore.txt';
$handle2 = fopen($readmore_file_path, "r");
$string2 = '';
while (!feof($handle2)) { $string2 .= fgets($handle2); }
fclose($handle2);
$strTxt = 'SYSTEM STATUS<br>';
if ('' != $string)
{
$strTxt .= $string;
if ('' != $string2) { $strTxt .= '. <a href="readmore.txt"> More details</a>'; }
$strTxt .= '<br>';
echo $strTxt;
}
我不确定该代码是否会导致内存泄漏。在我们拥有该代码后,RAM每天开始增加。不确定fopen()是否会导致泄漏? – 2012-02-08 02:12:24
@KhaHoang:RAM使用率可能会增加,因为这段代码会将这两个文件的全部内容读入内存。取决于文件的大小,这可能很重要。这听起来像是随着时间的推移文件变得越来越大,这意味着需要更多的RAM来将文件内容读入内存。考虑重写它以不将文件读入内存。看我的编辑。 – 2012-02-08 12:51:47