okconfused okconfused - 8 months ago 13
PHP Question

How to display large xml feed without putting pressure in memory php

I want to display very large XML-feeds without putting too much pressure on either the CPU or the memory. Because of that feeds can no longer be put into memory, but have to be processed in an alternative way.

I have two url to curl one is with limit:

and other is without limit: http://pf.tradetracker.net/?aid=1&type=xml&encoding=utf-8&fid=251713&categoryType=2&additionalType=2

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);
$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'>
<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 class='clear'> </div>
echo $html;
$return_html = ob_get_contents() ;
echo $return_html;

When I curl the url, it will take time to display and used memory.

Ali Ali

Try to use limit value as "50, 100".

http://pf.tradetracker.net/?aid=1&type=xml&encoding=utf-8&fid=251713&categoryType=2&additionalType=2&limit=50, 100

It will start record from 100 and limit to 50. So you can show record as per your requirement by using ajax call. It will not fetch all record at once.