$timeout, "usec" => 0]); // get string size // for some reason, not using msg_peek makes the second // socket_recv call hang if(socket_recv($sock, $strlen, 36, MSG_PEEK | MSG_WAITALL) === false){ throw new Exception("Failed to receive datalen"); } $strlen = unpack("c", substr($strlen, 34, 35))[1]; if(socket_recv($sock, $reply, (35 + $strlen), MSG_WAITALL) === false){ throw new Exception("Failed to receive string"); } $reply = substr($reply, 35, (35 + $strlen)); $reply = explode(";", $reply); if(count($reply) !== 3){ throw new Exception("Received malformed string"); } $reply = [ "game" => $reply[0], "type" => $reply[1], "name" => $reply[2] ]; return $reply; } }