Page 1 of 1

Embedding Problem

Posted: Fri Apr 21, 2006 12:26 pm
by dbu
Hello and thanks, s9y is a great tool!

I try to embed it into my web pages, where i use the phpcms system.
However, i use the ob_start() methods, but it does not work.

I brought it down to a minimal code showing the problem:

Code: Select all

ob_start();
chdir(dirname(__FILE__));
require('index.php'); //s9y
$x = ob_get_contents();
ob_end_clean();
echo $x;
When i point my browser to that file, i get a completely empty page with no content at all. Even putting echo 'test'; after ob_end_clean() does not show up.

As soon as i do some output before including index.php, i get the Warning: Can not modify header... lines, but then x is shown.
How can i make the ob_start()/ob_end_clean() stuff work?

I use 1.0-beta2. Is this a bug or am i doing something wrong?

(Edit: I just realized that commenting out the ob_end_clean() makes the page show - but it is printed automatically, if i leave the echo $x, i get it double. Is there something wrong with the ob_* calls inside s9y?)

Re: Embedding Problem

Posted: Fri Apr 21, 2006 1:05 pm
by garvinhicking
Hi!

I've heard this problem now for the third time, actually. The other problematic users where vinman and thereza:

http://www.s9y.org/forums/viewtopic.php ... obendclean
http://www.s9y.org/forums/viewtopic.php ... obendclean

Does any of it apply to you? Are you maybe also using PHP 4.3.11 as CGI? Do you have any means to test with a different PHP version?

To me it seems as if the PHP ob_* functions changed somewhen. With my PHP 5.1.2 installation everything works as expected! Serendipity does do nested ob_X calls, but every ob_start() also matches a ob_end_clean(), so this should be allright.

I'd love to get this sorted somehow?! :(

Regards,
Garvin

Posted: Fri Apr 21, 2006 4:15 pm
by thunderlove
I wish I had good news, but I don't. Just bad news :(

the ob_ functions are VERY picky -- even code like echo "Hello, $place" can mess it up. Error- and Warning- mesages DO mess it up, and the result is a blank page. I've been told this is (sort-of) documented

http://www.php.net/manual/en/function.ob-start.php

Notice in particular:
ob_end_clean(), ob_end_flush(), ob_clean(), ob_flush() and ob_start() may not be called from a callback function. If you call them from callback function, the behavior is undefined. If you would like to delete the contents of a buffer, return "" (a null string) from callback function. You can't even call functions using the output buffering functions like print_r($expression, true) or highlight_file($filename, true) from a callback function.
Error messages use callback functions, and (at least sometimes), so do variables embedded in strings. (the result is buffering functions might be called from within their callback functions) Please don't ask me to explain, because I'm not sure I understand, or even believe, the explanation

Someone else might know a better way, but the only way I know to debug this, is to first, turn off the ob_ functions (comment them out) and (hope) you spot an error or warning message. Fixing them will almost always get things to work. You may need to disable some plugins too.

If this doesn't work, you are probably going to need to go bug hunting. Turn the ob_ back on, and about half-way through, insert a
ob_end_flush(); ob_start(); If you see the top half, then you know the problem lies in the bottom half.... Eventually, you will be able to track down the trouble-maker.

Posted: Fri Apr 21, 2006 4:25 pm
by garvinhicking
Hi!

This might lead us in right on track, thanks a lot. I suggest to turn the error_reporting via php.ini or .htacces to E_ALL and switch display_errors On so that you might spot any errors on the way easily. Also going through your PHP and Apache errorlogfile might help spot the problem.

And like thunderlove pointed out, any plugins you installed might also be a possible culprit...

Regard,s
Garvin

Posted: Tue Apr 25, 2006 2:43 pm
by StarF
alright tnx for your help, seems i have the same problem as those i linked to.. if i remove the ob_clean part i still just get a white page...

i am gonna try to play a bit with it.. to find a solution.. so the next page can be viewed...

output

Posted: Thu Apr 27, 2006 6:59 pm
by dbu
well, i tried to debug, and when setting $serendipity['production'] = 'debug', i see a lot of Notice: error messages. however, usually, they are supressed and thus i think should not occur. (correct me if i am wrong)

Notice: Use of undefined constant CHARSET_NATIVE - assumed 'CHARSET_NATIVE' in /home/david/www/localhost/htdocs/serendipity/serendipity_config.inc.php on line 119

Notice: Undefined index: has_extended in /home/david/www/localhost/htdocs/serendipity/templates_c/carl_contest^%%69^69E^69ED8955%%entries.tpl.php on line 124

Notice: Undefined index: head_subtitle in /home/david/www/localhost/htdocs/serendipity/include/functions_smarty.inc.php on line 606

there is a lot more of them, all similar, but in different php scripts. does this help or am i on the wrong track with this?

Re: output

Posted: Fri Apr 28, 2006 10:31 am
by garvinhicking
Hi!

Sadly those "undefined index" messages are not really problematic, since you are right that they are usually surpressed. Usually they just try to save the "if isset(...)" match when using array keys, where an empty value doesn't hurt.

The problem should thus not be in "Notice" errors, but instead in "Warning" messages, I guess.

Sadly I myself don't know the real cause, since on my 3 servers I have available the output buffering works as expected. I might be able to help if someone can give me full FTP access to his s9y installation.

Regards,
Garvin

Disable Comments and Trackbacks

Posted: Thu May 04, 2006 4:30 am
by vinman
Since my spam has become an epidemic and I cannot get the latest s9y to work embedding-wise, I need to completely disable comments and trackbacks.

Didn't want to do that, but sadly, it's necessary.

So how do you DISABLE comments and trackbacks completely?

TIA

Re: Disable Comments and Trackbacks

Posted: Thu May 04, 2006 11:03 am
by garvinhicking
Hi!

In serendipity > 0.8 you can just edit your comments.tpl template and remove the template parts that work for comments.

With serendipity prior to 0.8 it would require patching up many files (include/functions_comments.inc.php). I don't know if the spamblock plugin existed for 0.7 already, but if so, you can just enable the emergency shutdown of all comments.

About the embedding problem, sadly no one yet reported back to me or gave me FTP access to their sites, so I'm at a loss and not able to help.

Best regards,
Garvin

Posted: Fri May 05, 2006 10:31 am
by dbu
I test it on my local machine, so i can not give you ftp access. I will upload the page and see whether i have the problem on the server too.
I tried to create a minimal example of the bug, but it did not work. I embed serendipity into phpcms, which makes the whole thing rather complicated. I found the following comment within class.lib_phpcms.php, but neither enforcing the additional ob_start to happen, nor making shure it does not happen did help. But maybe it helps something?

if (isset($DEFAULTS->FIX_PHP_OB_BUG) AND $DEFAULTS->FIX_PHP_OB_BUG == 'on') {
// starting aditional output buffer to fix a bug in php 4.2.3
// which causes the output buffer to fail when sessions are
// set within a script or plugin
ob_start();
}

I found out that for me, I can just omit the ob_start and ob_end_clean completely, as phpcms captures the output for me. (However, there is still a bug somewhere.)

Posted: Tue Jun 06, 2006 9:50 am
by palabran
I had the same problem. I donĀ“t know the exact cause, but removing line 475 "serendipity_gzCompression();" in "index.php" fixed it for me.

Timo