ccampbell / chromephp

class for logging PHP variables to Google Chrome console
http://www.chromelogger.com
1.38k stars 450 forks source link

how can i log after i already sent some data? #60

Closed beppe9000 closed 7 years ago

beppe9000 commented 7 years ago

I have a php script that streams real-time logs and does some operations based on those logs. Is it ok to log after the headers and part of body have already been sent?

ccampbell commented 7 years ago

Hi @beppe9000. No, that is not possible. The logging requires sending an HTTP header which has to be sent before the request body. What you can do is use output buffering in your application, but that is outside the scope of this project.

beppe9000 commented 7 years ago

My php script must be in real time, as the data is continuously updated and the script has a very long execution limit.

Maybe a scheme to buffer the logs could be added? For example the logs are stored in memory as a session variable, while the page outputs an "LogKey" header that is subsequently used as a parameter to an endpoint that outputs the stored logs. Every second the browser polls logs from the php endpoint, ending one second after the main page is done loading.