From Soldat Community Wiki
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
$ip = '127.0.0.1';
$port = 23073;
$start_time = microtime(true);
$sock = socket_create(AF_INET,SOCK_DGRAM,SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 5, "usec" => 1)); // 5 Second timeout
$packet = 'i'.chr(0); // Ping packet from Client -> Server (Lobby ping)
socket_sendto($sock, $packet, strlen($packet), 0x100, $ip, $port);
do {@socket_recvfrom($sock,$buffer,6,0,$ip,$port);} while(strlen($buffer) == 6);
$total_time = round((microtime(true) - $start_time)*1000);
if ($buffer == '') {
// Ping test failed, code here.
} else {
// Ping test passed, code here.
}