As an alternative, you can call per php file on execution a small function to record the IP and the time like so:
127.0.0.1|1093810181
Then, use a javascript call-back function to "listen" for an exit (either by link, closing browser, redirection or whatever) and have that call a different PHP page which will take the IP (which can be sent via JS) to open that same file, find the IP without a second time-stamp, append it.
Then when you do your calculations, it's a matter of reading the file, finding the line(s) with that IP address, taking each entry and splitting it into three parts:
IP address, start time, end time
Subtract the start time from the end time, gives you the total number of seconds available. Add all the seconds the user spent on the page, and voila!!
Alternatively, if you have a user management system, you can do something like what forums do. At each page execution a DB table is "touched" to update the session table. For every one of your actions you update the DB with the timestamp. If they leave it alone for longer than 5 minutes, you calculate the time spent on there, add it to their cumulative total, and then start over.