title: How can I ping a server port with PHP?
body: <p>I want a PHP script which allows you to ping an IP address and a port number (<code>ip:port</code>). I found a similar script but it works only for websites, not <code>ip:port</code>.</p>
  
  <pre><code>&lt;?php
  
  function ping($host, $port, $timeout) 
  { 
    $tB = microtime(true); 
    $fP = fSockOpen($host, $port, $errno, $errstr, $timeout); 
    if (!$fP) { return "down"; } 
    $tA = microtime(true); 
    return round((($tA - $tB) * 1000), 0)." ms"; 
  }
  
  //Echoing it will display the ping if the host is up, if not it'll say "down".
  echo ping("www.google.com", 80, 10);
  
  ?&gt;
  </code></pre>
  
  <p>I want this for a game server.</p>
  
  <p>The idea is that I can type in the IP address and port number, and I get the ping response.</p>