下面的代碼是否有可能的內存泄漏?我們有一個運行在PHP v5.3.3的Apache服務器上的網站,這個代碼被批評爲可能有內存泄漏。希望看到另外一組眼睛會幫助發現問題。這個XML代碼有沒有可能的PHP內存泄漏?
<?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++;
}
?>