FirePHP on Frameworks which makes use of ob_start()

7 messages Options
Embed this post
Permalink
akentner () FirePHP on Frameworks which makes use of ob_start()
Reply Threaded More More options
Print post
Permalink
Hi there,

I try to implement FirePHP in Dokuwiki (DW, http://www.dokuwiki.org). DW uses itself ob_start() and ob_get_contents() at some places. So everytime DW calls ob_get_contents() I get an exception from FirePHP (of course).

Is it possible to send FirePHP messages after the headers at runtime, like <script>console.log('bla bla');</script>

Or, are there other ideas?

Thanx

Alex
Christoph Dorn () Re: FirePHP on Frameworks which makes use of ob_start()
Reply Threaded More More options
Print post
Permalink
Output buffering segments can be nested. Try starting an extra ob_start() for FirePHP BEFORE the Dokuwiki one. Docuwiki will then flush it's buffer to the first buffer which will be automatically flushed at the end of the request.

Let me know if that works for you. If not I'll see what I can do to get it working.
Frank Ralf () Re: FirePHP on Frameworks which makes use of ob_start() (Moodle)
Reply Threaded More More options
Print post
Permalink
I am working on a FirePHP plugin for Moodle (http://moodle.org/mod/forum/discuss.php?d=119961) and got the same problem.

Everything works fine on my local development machine (Win 2000, XAMPP), but on a hostet Linux machine I got the following error message:

"Fatal error: Uncaught exception 'Exception' with message 'Headers already sent in /is/htdocs/wp1113681_O04QM8ZPI7/www/moodle/lib/weblib.php on line 2658. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.'..."

Shouldn't turn FirePHP output buffering off again somewhere so those other nested buffers won't get disturbed?

Kind regards,
Frank
Christoph Dorn () Re: FirePHP on Frameworks which makes use of ob_start() (Moodle)
Reply Threaded More More options
Print post
Permalink
You can open one or more buffers at the same time which will all get closed at the end of the request if they are still open. Closing a buffer will always close the last opened one first.

I would venture to say that you have output buffering enabled via the ini directive on your local system and the hosted linux server has it turned off.

You should be able to just start an all-encompassing output buffer for FirePHP at the very beginning (before Moodle is called) which Moodle will write it's output to. This buffer will then be flushed at the end of the request automatically.

Frank Ralf () Re: FirePHP on Frameworks which makes use of ob_start() (Moodle)
Reply Threaded More More options
Print post
Permalink
Hi Christoph,

You are right. I had set output_buffering = ON in the php.ini and totally forgotten that.

Actually, I am inclined to see this issue as a feature, not a bug ;-) You should enable FirePHP only on a development system anyway. And in that case you should be able to activate output buffering via the ini file instead of using ob_start(). So that would provide an additional layer of security. Or am I missing something?

Another possible solution I am considering is using the approach the Drupal for Firebug module/plugin uses (http://drupal.org/project/drupalforfirebug). Instead of using the header to send the debugging information to the Firebug console the module uses hidden <div> tags for that purpose which might be a more robust way.

But that would leave all the heavy lifting of formatting the output to such a module instead of resorting to FirePHP's powerful features...

Kind regards,
Frank

Christoph Dorn () Re: FirePHP on Frameworks which makes use of ob_start() (Moodle)
Reply Threaded More More options
Print post
Permalink
I am working on a new and more comprehensive server library for FirePHP that will allow you to enable and disable FirePHP via a configuration file. If you would like to become a beta tester, watch my blog for the announcement (http://www.christophdorn.com/).

Why do you not want to use output buffering? Is it a problem because you want to be able to install a FirePHP plugin into Moddle without requiring the user to add ob_start() at the beginning of the Moodle bootstrap file or requiring the user to enable output_buffering in the php.ini file?

Reverting back to <div> instead of headers is a big step backwards in my opinion. It does not allow debugging of any requests other than HTML and it will not take advantage of the current FirePHP variable renderer nor more powerful features I will be introducing later this year.

Let's figure out a solution that works for you. You are not the only one who will be running into this issue.

The two solutions I see right off the bat:

1) See why Moodle outputs content before your plugin is called. Is it a mistage (whitespace at the end of a PHP file) or is it intentional?

2) If it is possible to have the FirePHP plugin called before any Moodle output you can enable output buffering then. It does not have to be enabled right at the beginning, just before any output.
Frank Ralf () Re: FirePHP on Frameworks which makes use of ob_start() (Moodle)
Reply Threaded More More options
Print post
Permalink
Thanks for your quick reply.

You're right, setting output buffering in php.ini won't hurt anyone. There are also some other recommendations for setting up a custom php.ini for your Moodle installation.

Moodle itself makes extensive use of ob_start(), I counted more than 60 occurrences in over 40 files... So I'm still in the process of figuring out, where FirePHP's ob_start() fits in best ;-)

I'm looking forward to your new version of FirePHP.

Cheers,
Frank