I’ve developed a server-client application based on the following idea:
A Client (windows application) work with a Server (PHP webpages) mostly like a client-server application based on sockets. Client send raw data to a PHP webpage, PHP script will check/process received data and finally script return an answer to client (data accepted/rejected/etc.).
The basic idea is that the client “ping” the server every X seconds even there the client is active or not. What is the best solution to log client activity?
For example:
Client1 started application at Time1 and it "ping" Server for lets say 30 minutes, after that interval the Server stop receiving "pings" from the client;
Client2 started application at Time1+10min and it "ping" Server for lets say 40 minutes, after that interval the Server stop receiving "pings" from the client;
Client1 started application at Time1+35 and it "ping" Server for lets say 60 minutes, after that interval the Server stop receiving "pings" from the client;
** Server stop receiving "pings" from client means there is no activity for at least 1 minute
I need a final report who can give me the following data:
Client | Start at | End at | Active
=========+=============+=============+========
Client1 | Time1 | Time1+30min | 30min
Client2 | Time1+10min | Time1+50min | 40min
Client1 | Time1+35min | Time1+95min | 60min
I don’t have any clue how to make my MySQL log tables and what information to store in them via PHP for future reports.
Any questions/observations are welcome.
EDIT: I don’t need any PHP code to log my entryes, I don’t need MySQL CREATE TABLE or SELECT command from you. I just ask for a good way to store all records, and a good way to retrieve some information from them. Thanks for downvoting the post without reading it until the end.
@MoeTsao’s suggestion is not bad, considering you didn’t define the “X” in “X seconds”. If “X” was around 3600 or more, it wouldn’t be too bad. Maybe you got downvoted for being pissy to him instead of taking his idea and modifying based on your (now elaborated) value of “X”? As in…
Create a log table like this:
then, on every request, do an UPDATE:
Check how many rows were updated (see your coding manual for that).
If one row was updated, you’re done. If none were updated, it’s either a new client or a client that is idle and you must then do an insert:
(contrary to my pseudo-code, please use positional parameters in your queries).
Creating the report is trivial (all necessary columns are in the row you’re storing), and is left as an exercise for the original poster. 🙂