Question

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.

Was it helpful?

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...

OTHER TIPS

If you already have a ping function working, then it seems to me you can simply set up a cron job to run that script every minute (for example), and then store the results of your ping function in a database (MySQL or so).

Then when you view the status page, that page gets the latest records for all computers from the database, and shows whether they are online or offline. If they are online, you can calculate the difference between the current time and the time that particular computer was first seen online in the current session, and show the uptime for that system.

Of course, this assumes that you know the IP addresses these computers are running from will not change while they are online (unlikely though this may seem, it may be something you'll need to keep in mind).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top