DEV Community

Discussion on: A simple way to debug PHP applications.

Collapse
 
moopet profile image
Ben Sinclair

Hi Akshay.

I did something similar a while ago when I was frustrated with certain frameworks (Drupal I'm taking about you).

Something that stopped me from making it "complete" was output buffering. If you want the log messages to appear as they're processed, and not get delayed or removed by subsequent crashing parts of your program, you ideally want to send it out of band, but you can't do that with PHP directly.

What you can do is hack the output buffer:

$old_buffer = ob_get_clean();
echo "my script here"
ob_start();
echo $old_buffer;

This results in the message hitting the browser immediately... or at least it does if there's only one level of output buffering! You can (un)fortunately nest them, so that's not a complete solution either.

The other solution I had was to run a second process receiving log messages. In Drupal, that's effectively what drush ws --tail does, but you could write a web interface instead so you didn't have to leave your browser.

Collapse
 
akshaykhale1992 profile image
Akshay Khale

That is an interesting option, I will try to implement it, Thank you for the great suggestion.