Even though PHP is a server side script, you might think about another approach and use php to analyze your webserver log to estimate the time a customer has visited your site. Keep in mind, that this cannot be perfectly accurate (as any JS solution e.g. Google Analytics would be, too). It is just an approximation based on path analysis.
176.28.xx.xx - - [28/Apr/2013:19:26:04 +0200] "GET /page1 HTTP/1.1" 200 5552 "-" "-"
176.28.xx.xx - - [28/Apr/2013:19:26:05 +0200] "GET /page2 HTTP/1.1" 200 5552 "-" "-"
176.28.xx.xx - - [28/Apr/2013:19:26:06 +0200] "GET /page3 HTTP/1.1" 200 5552 "-" "-"
176.28.xx.xx - - [28/Apr/2013:19:26:07 +0200] "GET /page4 HTTP/1.1" 200 5552 "-" "-"
176.28.xx.xx - - [28/Apr/2013:19:31:04 +0200] "GET /page4 HTTP/1.1" 200 5552 "-" "-"
176.28.xx.xx - - [28/Apr/2013:19:31:05 +0200] "GET /page1 HTTP/1.1" 200 5552 "-" "-"
In this case you would find out, that there is one customer (based on the assumption, that a customer is uniquely identified by his IP address) that has two intervals of (based on the assumption that we put up a threshold of 1 minute, where a new visit of the same customer begins)
- 3 seconds from 28/Apr/2013 19:26:04 - 19:26:07
- 1 second from 28/Apr/2013 19:31:04 - 19:31:05
A tool already doing that is AWStats
Further readings can be found if you are looking for
- data mining
- path analysis
Bottom Line: But this is just an approach to answer your question. I would use tools like Piwik, Google Analytics or similar to track those. They are advanced and doing all the stuff for you, especially storing lots of plotting points, that are needed. Consider that such tracking tools increase the request rates to your webserver dramatically and since php needs to setup a database connection on each call, that tool you are seeking to build, will be quite expensive in server power.