我有一个下面的页面,它为用户加载图像,网址看起来像 someurl / page.php文件?路径= A.JPG 当人们访问此页面时,我发现内存使用量增加很快 我不确定这个页面是否会导致内存泄漏
<?php
$tar_path=urldecode($_GET['path']);
$strs=preg_split("/\./",$tar_path);
$small_name = $strs[0].'_small.'.$strs[1];
header('Content-type: image/jpeg');
if(file_exists($small_name))
{
$PSize = filesize($small_name );
$picturedata = fread(fopen($small_name, "r"), $PSize);
echo $picturedata;
}else
{
$im = imagecreatefromjpeg($tar_path);
$maxwidth = 150;
$maxheight = 0;
$pic_width = imagesx($im);
$pic_height = imagesy($im);
$widthratio = $maxwidth/$pic_width;
$resizewidth_tag = true;
$ratio = $widthratio;
$newwidth = $pic_width * $ratio;
$newheight = $pic_height * $ratio;
if(function_exists("imagecopyresampled"))
{
$newim = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
}
else
{
$newim = imagecreate($newwidth,$newheight);
imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
}
imagejpeg($newim,$small_name);
imagedestroy($newim);
imagedestroy($im);
$PSize = filesize($small_name );
$picturedata = fread(fopen($small_name, "r"), $PSize);
echo $picturedata;
}
?>
答案 0 :(得分:2)
浏览器或服务器的内存使用情况?
php解释器应该在结束脚本执行时释放所有内存。在这种情况下,服务器上的内存消耗可能会显示处理图像很重,但完成后应释放所有内存。