Jump to content

Unable to cache dynamic advertisements coming from a live url.


sunil_23413

Recommended Posts

 

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/?exportHeader=true&standAlone=true&disableLogin=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|1040245|18003|16|ADTECH;loc=100;key=;grp=18003;asfunc=1;misc=1237453012837"></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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.