Unable to cache dynamic advertisements coming from a live ur

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sunil_23413
Forum Newbie
Posts: 10
Joined: Thu Mar 12, 2009 5:43 am

Unable to cache dynamic advertisements coming from a live ur

Post 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.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

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

Post by php_east »

you had the problem, correctly diagnosed it, and found an answer.
what is your question ?
sunil_23413
Forum Newbie
Posts: 10
Joined: Thu Mar 12, 2009 5:43 am

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

Post 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.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

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

Post 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.
sunil_23413
Forum Newbie
Posts: 10
Joined: Thu Mar 12, 2009 5:43 am

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

Post 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
Post Reply