Is it possible to ping a server from Javascript?

后端 未结 17 1196
礼貌的吻别
礼貌的吻别 2020-11-22 04:02

I\'m making a web app that requires that I check to see if remote servers are online or not. When I run it from the command line, my page load goes up to a full 60s (for 8 e

17条回答
  •  执念已碎
    2020-11-22 04:54

    just replace

    file_get_contents
    

    with

    $ip = $_SERVER['xxx.xxx.xxx.xxx'];
    exec("ping -n 4 $ip 2>&1", $output, $retval);
    if ($retval != 0) { 
      echo "no!"; 
    } 
    else{ 
      echo "yes!"; 
    }
    

提交回复
热议问题