Hi all,
Can anybody help. I am nearing the ened of development of a shopping portal/price comparison site. The site has 2 scripts which display remote images (1 page has 1 image) and the other one has ten per page.
The problem i have is that the following function puts a delay of 5+ seconds on the page download time which will for sure cause people to abandon the site. The php script I show does not use the function but a simple $imagefilesize=(@fclose(@fopen($arrRet[$iLoop]["ImageURL"], "r"))); // returning 1 if file exists
The only solution i can think of is to locally save all these remote images during the datafeed XML import done each night but that would be a bit messy.
MYSQL function
function getremotefilesize($u){
if ($u==''){
$size = 0;
return $size;
}
$ourhead = "";
$url=parse_url($u);
$host=$url["host"];
$path=$url["path"];
$fp = @fsockopen($host, 80, &$errno, &$errstr, 1);
if(!$fp) {
echo("error");
exit ();
} else {
fputs($fp,"HEAD $u HTTP/1.1\r\n");
fputs($fp,"HOST: dummy\r\n");
fputs($fp,"Connection: close\r\n\r\n");
while (!feof($fp)) {
$ourhead = sprintf("%s%s", $ourhead, fgets ($fp,128));
}
}
fclose ($fp);
$split_head = explode("Content-Length: ",$ourhead);
$size = round(abs($split_head[1])/1024);
return $size;
php script
for($iLoop=$start;$iLoop<$end;$iLoop++) {
$image = @getimagesize($oProds[0]["ImageURL"]);
$imageWidth = $image[0];
$imageHeight = $image[1];
if ($imageWidth > 100 && $imageHeight >0) {
$imageratio = $imageWidth / $imageHeight;
$newimagewidth = 175;
$newimageheight = $newimagewidth / $imageratio;
}
if ($imageWidth < 1){
$noimage = 1;
}
echo'<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="500" id="AutoNumber1">
<tr>
<td width="90" rowspan="3">';
$imagefilesize=(@fclose(@fopen($arrRet[$iLoop]["ImageURL"], "r")));
if (((strpos($arrRet[$iLoop]["ImageURL"], '.jpg') ===false) && (strpos($arrRet[$iLoop]["ImageURL"], '.gif') ===false)) || ($imagefilesize<1)) {
echo '<p><img border="0" src="../common/noimage75wide.gif" width="75" height="45"></p>';
} else {
echo'<a target="_blank" href="';
echo $arrRet[$iLoop]["ProductURL"];
echo'"><img border="0" src="';
echo $arrRet[$iLoop]["ImageURL"];
echo'" width="70">';
echo'</a>';
}
echo'</td>
<td width="332" class="MPPtitle" colspan="2">';
if ($arrRet[$iLoop]["ProductBrand"]!=''){
echo $arrRet[$iLoop]["ProductBrand"];
echo ' - ';
}
echo $arrRet[$iLoop]["ProductName"];
echo ' (from ';
echo $arrRet[$iLoop]["Merchant"];
echo')';
echo'</td>
</tr>
<tr>
<td width="332" class="MPPtext">';
if (strlen($arrRet[$iLoop]["ProductDesc"]) <130) {
echo $arrRet[$iLoop]["ProductDesc"];
} else {
echo substr($arrRet[$iLoop]["ProductDesc"],0,130);
echo'...';
}
echo'</td><td width="70"> </td></tr><tr><td width="262" class="MPPtext">Price: <font color="#FF0000">£';
echo $arrRet[$iLoop]["ProductPrice"];
echo'</font></td>
<td width="70" ><a target="_blank" href="';
echo $arrRet[$iLoop]["ProductURL"];
echo'"><p align="center"><img border="0" src="../common/infobuy.gif" width="61" height="17"></a></td>
</tr>
<tr>
<td colspan="3" width=500"><hr color="#000000" size="1"></td>
</tr>
</table>
</center>
</div>';
}
Any clues?
Any help would be appreciated.
Cheers
Darren