I am implementing a logging function and I would like to keep track of how much data a request to my PHP script returns to the client.
Basically I want to add a logger in the end of my function that determines the time the request took (using microtime() function), how much memory was used at peak (using memory_get_peak_usage() function) and how much data was returned to the client (basically how much data my script output generates, even if this was not actually sent to the client). This allows me to basically calculate the approximate possible bandwidth my script generates per request.
Now, I do know that I could use ob_*() series of functions that deal with output buffer, but I am already using these functions across the script in number of places and I don’t want to suffer from performance hit when adding another layer on top of everything.
Is there a function I could use in PHP that tells me at any point in the script how much output data has been generated by my script so far?
Thanks!
PHP does not keep an internal count of what you have sent to the client so far (that would be adding another layer on top of everything, even for those who do not need this functionality), so there is nothing you can do except using the output buffering functions to gather content before sending it.
Did you actually try wrapping more output buffering around your script and found the performance difference unacceptable?