Page 1 of 1

Unable to cache dynamic advertisements coming from a live ur

Posted: Thu Mar 19, 2009 4:49 am
by sunil_23413
Hi there, I am fetching external header (any content) from a live site. And I am cacheing it for 2 minutes using the method ob_start().The code s given below:
check2.php
<?php
$cacheFile = 'cache.html';
$t2=(filemtime($cacheFile));
$t=time();
$d=$t-$t2;
if ($d<120)
{
$content = file_get_contents($cacheFile);
echo "in cache";
echo $content;
}
else
{
echo "not in cache";
ob_start();
$blog_baseurl="http://internetworld.idg.se/";
$url = "http://internetworld.idg.se/?exportHead ... Login=true";
$sideTopPage =file_get_contents($url);
$replaceArray = array('src="/');
$sideTopPage = str_replace($replaceArray, 'src="'.$blog_baseurl, $sideTopPage);
$replaceArray = array('href="/');
$sideTopPage = str_replace($replaceArray, 'href="' . $blog_baseurl, $sideTopPage);
echo $sideTopPage;
$content = ob_get_contents();
ob_end_clean();
file_put_contents($cacheFile,$content);
echo $content;
ob_end_clean();
}
?>

the above code is generating a cahe file named cache.html. But this cached file(cache.html) is also not loading very fast. The only reason is that cached file (cache.html) contains the following code due to which some adds are coming.

<div class="adContainer">
<script type="text/javascript" src="http://adserver.adtech.de/addyn|3.0|506 ... "></script>
<script type="text/javascript">showHeliosAd(1040245, 18003, false)</script>
</div>
So due to the above code cached content is not loading fast. If I remove the above code from cached file (cache.html) then cached content is loading extremely fast
So in the end I can say that the major problem is regarding the cacheing of dynamic advertisement that are fetched using a JavaScript. any suggestions are most welcome.

Re: Unable to cache dynamic advertisements coming from a live ur

Posted: Thu Mar 19, 2009 5:08 am
by php_east
you had the problem, correctly diagnosed it, and found an answer.
what is your question ?

Re: Unable to cache dynamic advertisements coming from a live ur

Posted: Thu Mar 19, 2009 5:15 am
by sunil_23413
but i can't remove the following code from cached content(cache.html)
<div class="adContainer">
<script type="text/javascript" src="http://adserver.adtech.de/addyn|3.0|506 ... "></script>
<script type="text/javascript">showHeliosAd(1040245, 18003, false)</script>
</div>

as this is the code due to which dynamic advertisements are coming.Due to this code cached content is not loading fast.

Re: Unable to cache dynamic advertisements coming from a live ur

Posted: Thu Mar 19, 2009 5:42 am
by php_east
it is slowed down only when you say echo $content, not when you file_get_contents.
of course you can remove it.

Re: Unable to cache dynamic advertisements coming from a live ur

Posted: Thu Mar 19, 2009 7:16 am
by sunil_23413
but echo statement is used to display all the content.how can i skip it i.e. echo statement is displaying all the external content