From c15f8cfda6df1c55724559907ff641223195712c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 12 Dec 2012 00:27:14 +0100 Subject: [PATCH] Removed restart command due to a huge memory leak ... Caused by free'd objects looped looping around itself calling each one and become HAL --- classes/API/ConsoleAPI.php | 6 +++--- classes/API/ServerAPI.php | 2 ++ classes/PocketMinecraftServer.class.php | 2 +- common/config.php | 1 + server.php | 4 +++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/classes/API/ConsoleAPI.php b/classes/API/ConsoleAPI.php index 026fd855c..7c5fd8ea0 100644 --- a/classes/API/ConsoleAPI.php +++ b/classes/API/ConsoleAPI.php @@ -48,11 +48,11 @@ class ConsoleAPI{ console("[INFO] Stopping the server..."); $this->server->close(); break; - case "restart": + /*case "restart": console("[INFO] Restarting the server..."); $this->server->api->restart = true; $this->server->close(); - break; + break;*/ case "banip": $p = strtolower(array_shift($params)); switch($p){ @@ -179,7 +179,7 @@ class ConsoleAPI{ console("[INFO] /whitelist: Manages whitelisting"); console("[INFO] /banip: Manages IP ban"); console("[INFO] /stop: Stops the server"); - console("[INFO] /restart: Restarts the server"); + //console("[INFO] /restart: Restarts the server"); foreach($this->help as $c => $h){ console("[INFO] /$c: ".$h[0]); } diff --git a/classes/API/ServerAPI.php b/classes/API/ServerAPI.php index 26f16339c..725748759 100644 --- a/classes/API/ServerAPI.php +++ b/classes/API/ServerAPI.php @@ -260,6 +260,8 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run public function start(){ $this->server->start(); + unregister_tick_function(array($this->server, "tick")); + unset($this->server); return $this->restart; } diff --git a/classes/PocketMinecraftServer.class.php b/classes/PocketMinecraftServer.class.php index e4d58865e..0ce30e5ed 100644 --- a/classes/PocketMinecraftServer.class.php +++ b/classes/PocketMinecraftServer.class.php @@ -242,7 +242,7 @@ class PocketMinecraftServer extends stdClass{ public function start(){ declare(ticks=15); register_tick_function(array($this, "tick")); - $this->event("onTick", "tickerFunction", true); + $this->event("onTick", array($this, "tickerFunction")); $this->event("onReceivedPacket", "packetHandler", true); register_shutdown_function(array($this, "close")); $this->loadMap(); diff --git a/common/config.php b/common/config.php index d6891130d..fa9266e49 100644 --- a/common/config.php +++ b/common/config.php @@ -26,6 +26,7 @@ the Free Software Foundation, either version 3 of the License, or */ set_time_limit(0); +gc_enable(); error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); ini_set('default_charset', 'utf-8'); diff --git a/server.php b/server.php index 1833f6530..4da6f3cb8 100644 --- a/server.php +++ b/server.php @@ -35,6 +35,8 @@ while(true){ if($server->start() !== true){ break; + }else{ + $server = null; + console("[NOTICE] The server is restarting... (".gc_collect_cycles()." cycles collected)", true, true, 0); } - console("[NOTICE] The server is restarting...", true, true, 0); }