Hi,
I have a script which retrieves a shop catalogue and formats the output to provide a feed an affiliate scheme.
I have set up the script to produce one feed and this works fine.
I have implemented a similar class to produce a feed with different fields and format the output.
This is set up to write the output to a file or print to a browser.
The problem is that the script will not output the entire catalogue to the browser unless the error_reporting is not suppressed.
If I allow the "trigger_error" output to be shown, the entire catalogue shows up fine, otherwise I get no output.
It has the symptoms of being a memory problem, but I have a track on the memory usage and I am iterating through the catalogue, one item at a time to reduce the amount of data I have to hold in arrays. Memory usage appears tiny, compared to the limit of 20M (Increasing to 64Mb has no effect).
The problem appears to be in the following function which basically translates the data from the shop data fields to the feed data fields. This is called with an associative array and will return the array which is then printed or written to a file. Some of the parts are commented out as allowing long string lengths makes the script fall over.
/**
_formatItem maps the data from our Catalogue fields to the format required by AffiliateFuture.
This falls over if the length of the LongDesc and ShortDesc fields are allowed to be 4000 and 1000 characters
respectively - there is no error in the log and the error handler does not show any problems, we just get a blank screen
*/
function _formatItem(&$item) {
global $mem_limit;
trigger_error("_formatItem
() " .memory_get_usage() ."/" .$mem_limit);
global $gBaseURL;
global $gImgURL;
$formatted = array();
$formatted['ProductName'] = stripslashes($item['ProdNa
me']);
$formatted['Brand'] = stripslashes($item['BrandN
ame']);
$formatted['Category'] = stripslashes(ucwords(strto
lower($thi
s->current
Category))
);
$formatted['Subcategory'] = stripslashes(ucwords(strto
lower($thi
s->current
SubCategor
y)));
$newlines = array($this->newline, "\n");
$desc = stripslashes(str_replace($
newlines, array(" ", " "), $item['ProdDesc']));
/*Truncate "LongDescription to N characters - try to do it nicely on a fullstop then a space*/
/*
$max = 4000;
$offset = 3500;
if($max <= strlen($desc)) {
$pos = strpos($desc, array(".", " "), $offset);
if(FALSE != $pos) {
$desc = substr($desc, 0, $pos);
} else {
$desc = substr($desc, 0, $max-1);
}
}
*/
$formatted['LongDescriptio
n'] = substr($desc, 0, 1000);
/* Repeat for short description...*/
/*
$max = 200;
$offset = 150;
if($max <= strlen($desc)) {
$pos = strpos($desc, array(".", " "), $offset);
if(FALSE != $pos) {
$desc = substr($desc, 0, $pos);
} else {
$desc = substr($desc, 0, $max-1);
}
}
*/
$formatted['ShortDescripti
on'] = substr($desc, 0, 200);
$formatted['Product URL'] = $gBaseURL ."shop.php?cmd=viewitem&ca
t=" .$item['CategoryID'] ."&id=" .$item['ID'];
$formatted['Image URL'] = $gImgURL ."images/catalogue/" .$item['ImageDetail'];
//$formatted['RRP'] = $item['PriceIncVat'];
$formatted['OfferPrice'] = $item['PriceIncVat'];
$formatted['Availability']
= "Check Site";
$formatted['DeliveryCost']
= $this->shippingCost;
$formatted['DeliveryLeadDa
ys'] = "Next Working Day";
//$formatted['PromoText'] = "";
return $formatted;
}
Any light shed on this would be very useful.
Cheers
Glen