【发布时间】:2016-05-01 06:15:03
【问题描述】:
我想显示非常大的 XML 提要,而不会对 CPU 或内存造成太大压力。因此,无法再将提要放入内存,而必须以其他方式处理。
我有两个 url 来 curl 一个是有限制的: http://pf.tradetracker.net/?aid=1&type=xml&encoding=utf-8&fid=251713&categoryType=2&additionalType=2&limit=5000
其他没有限制:http://pf.tradetracker.net/?aid=1&type=xml&encoding=utf-8&fid=251713&categoryType=2&additionalType=2
<?php
ini_set('memory_limit', '32M');
$feed_url = "http://pf.tradetracker.net/?aid=1&type=xml&encoding=utf-8&fid=251713&categoryType=2&additionalType=2&limit=5000";
$c = curl_init($feed_url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$xmlstr = curl_exec($c);
curl_close($c);
$xml_feed_obj = json_decode(json_encode((array) simplexml_load_string($xmlstr)), 1);
foreach($xml_feed_obj as $products_feed)
{
foreach($products_feed as $feed)
{
$html = "<link href='http://localhost/task/style.css' rel='stylesheet' type='text/css' />
<div class='rightcontainer' style='margin-top:10px;'>
<div class='flexslider carousel'>
<ul class='slides'>
<li>
<img src='".$feed->imageURL."' width='80' height='80'/>
<div class='caption-info'>
<div class='caption-info-head'>
<div class='caption-info-head-left'>
<h4>Product Name: ".$feed->name."</h4><br>
<span>Price: ".$feed->price."</span>
</div>
<div class='clear'> </div>
</div>
</div>
</li>
</ul>
</div>
</div>";
ob_start();
echo $html;
$return_html = ob_get_contents() ;
}
}
echo $return_html;
?>
当我 curl url 时,显示和使用内存需要时间。
【问题讨论】:
-
json_decode(json_encode((array)你想用这个实现什么? -
我希望将 xml 数据放入数组中,但这不是我的问题,我的问题是处理大型 xml 提要