正常运行时远程计数器php

正常运行时远程计数器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.

我想要的是我对webdev的基本知识。 p>

我正在寻找一种方法来开发一个PHP计数器,以显示网络上有一台在线计算机的时间(因为他应该通过对我认为的那台机器的ping来解决)。 p>

示例: p>

计算机1: ONLINE - 02:45:02 h(仍然实时向上计数) p>

给定刷新 在页面上,状态可能会更改为: p>

计算机1: OFFLINE - 00:00:00 h(可能是计算机已关闭) p>

当另一个刷新页面时,状态可能会变为: p>

计算机1: ONLINE - 00:00:01 h(再次联机,开始新计数) p>

我已经有一个ping函数了。 p>

额外:我可能需要在一种LOG中注册这些状态的变化,但我现在把它放到后台! p>

编辑:我在php中问它,但它可以通过简单的方式完成,我正在听你的! 我为一些英语错误而苦恼:) p>

我希望我也向我解释过! 既然感谢你的关注。 p> div>

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

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