下面的代码是否可能存在内存泄漏?我们有一个使用 PHP v5.3.3 在 Apache 服务器上运行的网站,该代码被批评为可能存在内存泄漏。希望另一双眼睛看着这个会帮助发现一个问题。
<?php
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/users/UFDeptHousing/uploads';
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
?>
<?php
// iterate over entries in feed
$i = 0;
foreach ($sxml->entry as $entry) {
if($i < 4) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[1]->attributes();
$thumbnail = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
?>
<tr>
<td width="95">
<span class="thumbnail"><a href="<?php echo $watch; ?>"><img src="<?php echo $thumbnail;?>" width="85" height="48" alt="<?php
$varlength = strlen($media->group->title);
if ($varlength > 30) {
echo substr($media->group->title,0,30)."...";
}else {
echo $media->group->title;
} ?>" /></a></span>
</td>
<td width="130">
<span class="title"><a href="<?php echo $watch; ?>">
<?php
$varlength = strlen($media->group->title);
if ($varlength > 30) {
echo substr($media->group->title,0,30)."...";
}else {
echo $media->group->title;
} ?>
</a></span>
<span class="length">Length: <?php printf('%0.2f', $length/60); ?></span>
</td>
</tr>
<?php
}
$i++;
}
?>