From 46ded9e6750e4d3dcfb3ef51aa50de6db1d4fa74 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 26 Dec 2012 02:59:30 +0100 Subject: [PATCH] Future all-memory impossible cleanup --- common/functions.php | 23 +++++++++++++++++++++++ server.php | 10 ++++++++++ 2 files changed, 33 insertions(+) diff --git a/common/functions.php b/common/functions.php index 0efc7f96a..82b44061a 100644 --- a/common/functions.php +++ b/common/functions.php @@ -26,6 +26,29 @@ the Free Software Foundation, either version 3 of the License, or */ +function hard_unset(&$var){ + if(is_object($var)){ + $unset = new ReflectionClass($var); + foreach($unset->getProperties() as $prop){ + $prop->setAccessible(true); + @hard_unset($prop->getValue($var)); + $prop->setValue($var, null); + } + $var = null; + unset($var); + }elseif(is_array($var)){ + foreach($var as $i => $v){ + hard_unset($var[$i]); + } + $var = null; + unset($var); + }else{ + $var = null; + unset($var); + } +} + + function parseNBTData($data){ $x = array(); if(isset($data["value"])){ diff --git a/server.php b/server.php index 86a4cbd86..e9fc7bd52 100644 --- a/server.php +++ b/server.php @@ -23,7 +23,17 @@ while(true){ if($server->start() !== true){ break; }else{ + console("[INFO] Cleaning up..."); + hard_unset($server); + $excludeList = array("GLOBALS", "_FILES", "_COOKIE", "_POST", "_GET", "excludeList"); + foreach(get_defined_vars() as $key => $value){ + if(!in_array($key, $excludeList)){ + $$key = null; + unset($$key); + } + } $server = null; + unset($server); console("[NOTICE] The server is restarting... (".gc_collect_cycles()." cycles collected)", true, true, 0); } }