Page 1 of 1

Problem with ob_end_clean when embedding

Posted: Wed Oct 25, 2006 12:41 am
by oeli
Hi,

I've read the embedding documentation and I understand what I have to do to get it to work. I'm almost there, but I'm running into a weird issue.

First, I created a simple blog.php which does nothing more than include('index.php'). I changed the indexFile directive and turned on embed mode. So far so good. Browsing serendipity/index.php or serendipity/blog.php gives me a nice plain html, embeddable html snippet.

Now I need to wrap this in output buffering, because I need to include the rest of my site first, then output the s9y output somewhere in between. So I changed my code to this:

Code: Select all

  ob_start();
  include("index.php");
  
  $s9y_output = ob_get_contents();

  ob_end_clean();
  echo $s9y_output;
Nothing more, nothing less. You'd say this is the most basic embed that should work right? Wrong, I get a blank page when I load this.

The funny thing is, if I remove the ob_end_clean, it works. (although I get the output double of course). So it seems the include is alright, it's just that I get a blank page as soon as ob_end_clean() is being called.

To check if this is caused by s9y, I removed the include, and just put an 'echo "Hello World"' in its place. If I do that, everything works. The ob_end_clean works fine, and the echo of $s9y_output displays "Hello World".

So there's something inside the serendipity include that, together with ob_end_clean, wreaks havoc. Maybe some mismatched internal ob_start/ob_end_clean inside s9y? Maybe some bug in output buffering in PHP? (can't really imagine what that would be).

It's only about 6 lines of code and I haven't even inserted my own cms stuff yet; but I've tried everything I can, and nothing seems to get it working. If I can't use ob_end_clean, I can't save the output for later display in the page.

Any ideas?

Posted: Wed Oct 25, 2006 12:57 am
by oeli
Thanks to this thread:

http://s9y.org/forums/viewtopic.php?t=5216

I was able to solve the issue.

Instead of commenting out the line mentioned in the last reply, I just went to the admin page and in the configuration, turned of output compression. That solved the problem.

(I also wanted to post this in said thread, but somehow the reply button in that thread just takes me to the forum index)

Maybe this could be noted in a 'known issues' section in the embedding documentation?

Posted: Wed Oct 25, 2006 9:51 am
by garvinhicking
Hi!

Great you were able to solve this! I've added your finding to the s9y documentation, that's a good suggestion!

Best regards,
Garvin