title: PHP ping Minecraft Server using cURL
body: <p>Helo all,
  I have a script that was created for pinging a Minecraft Server using fsockopen. I was wondering if there was a way to convert it to use cURL instead?</p>
  
  <p>Here is the function:</p>
  
  <pre><code>function pingserver($host, $port=25565, $timeout=30) {
  //Set up our socket
  $fp = fsockopen($host, $port, $errno, $errstr, $timeout);
  if (!$fp) return false;
  
  //Send 0xFE: Server list ping
  fwrite($fp, "\xFE");
  
  //Read as much data as we can (max packet size: 241 bytes)
  $d = fread($fp, 256);
  
  //Check we've got a 0xFF Disconnect
  if ($d[0] != "\xFF") return false;
  
  //Remove the packet ident (0xFF) and the short containing the length of the string
  $d = substr($d, 3);
  
  //Decode UCS-2 string
  $d = mb_convert_encoding($d, 'auto', 'UCS-2');
  
  //Split into array
  $d = explode("\xA7", $d);
  
  //Return an associative array of values
  return array(
      'motd'        =&gt;        $d[0],
      'players'     =&gt; intval($d[1]),
      'max_players' =&gt; intval($d[2]));
  }
  </code></pre>
  
  <p>It seems that this function only works when running on a local server, which is why I want to convert it to cURL so I can run it on a remote server.</p>