Question

I am using a function to ping some remote IP's inside and ajax request. It works fine if ping is a success, but if there is no response, the server seems to freeze and I have to close the browser. But if I enter the same shell function directly into command line, the timeout works. Also, it works fine on my local machine (WAMP) using -n.

function

public function ping_node($u_ip) {

    exec("/bin/ping -c 2 -w 2 " . $u_ip, $output, $result);

    if ($result == 0){
        return array("ok",$output);
    }else{
        return "fail";
    }
}

}
Was it helpful?

Solution

I never could get that to work, instead I used fsockopen. It works great and its much quicker.

function ping_node($ip){
  $socket = @fsockopen($ip, "102", $errorNo, $errorStr, 3);
    if(!$socket) return "fail";
  else return "ok";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top