Search code examples
phpcounterpinguptime

uptime remote counter php


What I want is a little beyond of my basic knowledge on webdev.

Im looking for a way to develop a php counter to show me how much time there is an online computer on a network (as he ought to be settled by a ping to that machine i think).

example:

Computer 1: ONLINE - 02:45:02 h (still up-counting in realtime)

Given a refresh on the page, the state may change to:

Computer 1: OFFLINE - 00:00:00 h (maybe computer has turned off)

As another refreshing the page, the state may change to:

Computer 1: ONLINE - 00:00:01 h (again online, starting new count)

Ive already a ping function working.

Extra: I may need to register these changes of state in a kind of LOG, but I put that to the background for now!

edit: im asking it in php, but it could be done in a easy way, im listening you! Im srry for some english mistakes :)

I hope I have explained to me as well! Since already grateful for your attention.


Solution

  • Another option would be to have a simple ajax call that continually updates a database record based on the user's IP address. You could have it run every 10 seconds or 30 seconds or whatever you like. All you would need to do is create a MySQL table that stores the user's IP the datetime the entry was created then a last recorded datetime. Each ajax call it checks to see if there is a row with the same IP and a last recorded datetime within your interval (10 seconds or whatever you set it to), if so just update the last recorded datetime, if not insert a new row.

    On your php page you would then check for any records that had last recorded datetime within your setup interval (10 seconds for example) if so they you can use a javascript/jquery clock to show you the time that has elapsed since the datetime the record was created.

    Another option that would be easier is to simply install Google Analytics, they have a new Realtime feature where you can see in real-time who is on your site, what page they are looking at, etc...