Question

I got a very strange problem. Today I tried to implement caching into my PHP application.

It works like a charm on my localhost WAMP server (Windows 8). But it does not work online.

Hence I do not have a clue what I am doing wrong.

The code is somewhat like:

<?php

function write_cache(){
$contents = ob_get_contents();

/// do something with contenst (like writing it..
}

$tpl_content = 'loooooong string'; // gets filled throughout the application

echo $tpl_content;

/// should be filling the cache
write_cache();

?>

This should work. I echo it hence it is in the buffer. And I am somewhere doing it correctly because locally it is working.

But online it remains empty..

Does anyone know what I am doing wrong??

Thanks in advance!!

Was it helpful?

Solution

@faintsignal

You where right!! ob_start(); was missing. It is probably not needed on a WAMP server.

But on a LAMP server it is needed.

The code now looks like:

<?php

ob_start();

function write_cache(){
$contents = ob_get_contents();

/// do something with contenst (like writing it..
}

$tpl_content = 'loooooong string'; // gets filled throughout the application

echo $tpl_content;

/// should be filling the cache
write_cache();

?>

And it works!!

Thanks!!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top