1

I'm building an application which uses load balancing to transfer users to another server. However i want to use a more smart solution than simple redirecting.

It is possible to ping the client's IP somehow using PHP or a simple Unix Command. I want to transfer the user to the server with the lower ping.

Tomasz Kowalczyk
  • 10,472
  • 6
  • 52
  • 68
OhGodWhy
  • 165
  • 1
  • 11

1 Answers1

1

I found this: Pinging an IP address using PHP and echoing the result

Specifically:

pingresult = exec("/bin/ping -n 3 $ip", $outcome, $status);

Or this: PHP - get server to ping a visitors IP and return the ping in ms

<?php

$out = array();
exec('ping -c 4 '.$_SERVER['REMOTE_ADDR'], $out);
print_r($out);

?>

EDIT

You could try using microtime to measure the execution on the server (which should account for network travel time as well)

Accurate way to measure execution times of php scripts

Community
  • 1
  • 1
Anthony
  • 107
  • 5
  • Yes but in most cases a server is unable to ping the given IP so pinging like this isnt not an option. Could a script that sending data to client and measure the total time taken to transfer the data would work? – OhGodWhy Dec 04 '14 at 19:41
  • I have added an edit. As per your original question, you specifically mentioned the use of a UNIX command. It should be noted that your clients are unreachable by a standard ping. – Anthony Dec 04 '14 at 19:45