class Unloader extends CI_Loader {
public function __construct() {
parent::__construct();
}
public function ci($objects = []) {
$CI =& get_instance();
foreach ($objects as $object) {
if (isset($CI->load->_ci_classes[$object])) {
unset($CI->load->_ci_classes[$object]);
}
if (isset($CI->load->_ci_models[array_search($object, $CI->load->_ci_models, true)])) {
unset($CI->load->_ci_models[array_search($object, $CI->load->_ci_models, true)]);
}
if (isset($CI->{$object})) {
unset($CI->{$object});
}
}
return $this;
}
}
public function worker() {
while (true) { // infinite loop. The worker never dies.
$message = $this->getMessage();
if (!empty($messages)) {
$this->load->library('some_library');
$this->load->model('some_model');
// do something
// destruct model and library and remove from CI super object, but keep CI super object alive.
$this->unloader->ci(['some_model', 'some_library']);
}
}
}