Advertisement
GAMELASTER

Finding unused port

Aug 4th, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. $freePort = 22003; //toto je prvý port ktorý máš v DB
  2. $query = mysqli_query($db, "SELECT port FROM server ORDER BY port DESC"); //fetchuješ servere zotriedenie od najmensieho portu hore
  3. while($fetch = mysqli_fetch_assoc($query)) //btw assoc je rychlejsi ako array
  4. {
  5.   if($fetch["port"] != $freePort)
  6.   {
  7.     //kedze sa port nerovna tomu, ktory by mal nasledovat, port je volny :-)
  8.     break;
  9.   }
  10.   $freePort++;
  11. }
  12. echo "Volny port: {$freePort}";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement