On most of my sites I have a simple logging system of all PHP page requests that I save to the database to have something easier to work with than Apache logs. I collect data such as URL, IP, host name, user agent, sometimes username, session ID, etc. I also collect the time the page took to render. The way I measure time is like this: at the start of the script (common index.php) I store microtime(true) in a global variable and then in my shutdown function I take another measurement and store the time duration. This works well in most cases but this measurement may also include the time the remote client took to download the page. While this knowledge is useful I'd also like to have a measurement of 'pure' PHP execution time excluding the network data travel.

Most of the pages are rendered with template engine (for example Smarty) but there are also pages that are rendered by a separate class (for example, XML reports, generated PDF pages, downloads, etc.). So there's really no uniform way of sending output to the client and there's no one particular final echo statement or ob_get_contents which I could precede with a microtime() measurement to know how much time PHP spent on executing the CPU intensive tasks of the script. Smarty uses output buffering so HTML pages are sent in one go, which makes the measurement accurate in most of the cases, however sometimes the network transfer times can add up to it.

I'm wondering, is there some universal way to measure the script execution time while ignoring the time it takes to send the page to a remote client?