2

I'm working on a Doctor-Patient project(Web+Android) where when patient books a token, it first checks if doctor is online or not; if it is online patient can book.

For this purpose I have used ping user IP approach i.e. when patient submits token, it pings at Doctor's IP and if he's online(has active internet connection) it registers patient token. But that seems not to be working as received data from ping indicates 100% packet loss.

Can't use flag setting which is triggered on doctor's last action which is not real time.

Please suggestion if you have solution for this issue.

<?php

// unset variables first to avoid mixing the results from previous calls
// 0 for success, 1 for packet loss, 2 for other error.
$retval=-1;
$output=array();
exec("ping 127.0.0.1 -c2 -w2 2>&1",$output,$retval);
echo "Return code: ".$retval."<br>\n";
echo implode("<br>\n",$output);

?>
Observer
  • 345
  • 1
  • 4
  • 21
  • Can you show what you did? – nekiala Jun 02 '17 at 10:22
  • @nekiala answer updated – Observer Jun 02 '17 at 10:31
  • Define "online". Does their machine just have to be connected to the internet and switch on - or does the Doctor have to be logged in to a webpage? – Tom Jun 02 '17 at 10:37
  • @thebluefox have to be connected to the internet and switch on – Observer Jun 02 '17 at 10:39
  • If I understand correctly, the patient submits the token from an Android app? I got this result : `Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms` – nekiala Jun 02 '17 at 10:40
  • @nekiala try your ip address, it won't work. It works for websites but not for User IP – Observer Jun 02 '17 at 10:42
  • I just tried with my ip address, also with an other internet ip address, both works. `Ping statistics for 192.168.188.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms` – nekiala Jun 02 '17 at 10:50
  • The patient submits the token from the web application or from the android application? Are the two apps in the same network? – nekiala Jun 02 '17 at 10:54
  • that's strange coz at my side it's showing 100% packet loss on your ip address as well. can you share link? or try with my ip 49.35.5.230 – Observer Jun 02 '17 at 10:55
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/145716/discussion-between-observer-and-nekiala). – Observer Jun 02 '17 at 10:56

4 Answers4

0

Many sites ignore ICMP (ping). If you have the doctor have his machine turn off the ICMP filtering, that may do it.

mikep
  • 3,841
  • 8
  • 21
  • can you elaborate more about ICMP and how it shall work – Observer Jun 02 '17 at 10:32
  • Many firewalls will reject ICMP (ping) requests. If your doctor has done so and has control of his firewall, then he needs start responding to ICMP requests. (I've simplified somewhat: see https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol fo details). This may not be the problem; I was just guessing. – mikep Jun 02 '17 at 10:43
0

insert a flag in user table means add extra column in your user table. when user is login make a flag on . when a user can logout off that flag. e.g |is_login| 1

or |is_login| 0

then it is easy any where you can query from database and can check that the doctor is online or offline.

zarif khan
  • 81
  • 6
0

Okay, so how I have understood your question, you want to know check if the doctor is using your website/app or not at the moment. So, this can be done by adding one more field to the database. Let's call this User_activity. Now, When a user logs in you can store the time in this field then you can make a query to see who all have this time in last 5-10 minutes(as per your requirement). Now, once you have done this you can ping the user in every 60 seconds to check whether the user is still there or not and from here you can update your database field as well. So, by this, you can check who is online and who is not.

var checkstatus = setInterval(function () {
    /* jQuery - back to server*/
    $.get("checkstatus.php");
 }, 60000);
Vikas Meena
  • 322
  • 3
  • 20
0

Problem is solved through 'EventSource' Method in JavaScript.

Just include var source = new EventSource("set_online.php");

Include above line in each page.

Then on set_online.php set online-status flag which will be updated in database.

That's it! as long as you are on that page user is set online thus indicating he is connected to internet.

Observer
  • 345
  • 1
  • 4
  • 21
  • You don't need any javascript for this at all. Including "set_online.php" would probably suffice completely. Oh well... – walther Jun 02 '17 at 19:48
  • @walther please elaborate – Observer Jun 03 '17 at 06:59
  • You said you're setting some flag in your PHP file, but EventSource was created to get updates from the server, not to run code like this. If you need to run a code to set a flag, why not do it directly or by including the file? You also should keep track of time when exactly was the page visited and handle situations if the doctor closed the window or his session expired. Simple setting of a flag isn't particularly helpful in such scenarios. – walther Jun 03 '17 at 08:35
  • @walther consider a situation where doctor has no activity since last 2 hours but he's still active. In this case you can't track his online status by just 'set_online.php' as by this method he would only be treated online when there's some action from user side. – Observer Jun 03 '17 at 09:09
  • The doctor is considered to be online when there's an action from the user? What? Also you said there's no activity from him, yet he's still active? Maybe you should define what do you mean by "active" then? If you need to check if the doctor has the website open, you need to periodically update his status using ajax - again, I don't see how your current solution helps you with this. – walther Jun 03 '17 at 09:23
  • @walther https://stackoverflow.com/questions/44342431/is-it-reliable-to-use-eventsource-to-get-users-online-status – Observer Jun 03 '17 at 09:28