$value){ if(is_array($value)){ $this->{$n} = new StackableArray(); call_user_func_array(array($this->{$n}, "__construct"), $value); } else{ $this->{$n} = $value; } } } public function __destruct(){ } public function run(){ } } class AsyncMultipleQueue extends \Thread{ public $input; public $output; public $stop; public function __construct(){ $this->input = ""; $this->output = ""; $this->stop = false; $this->start(); } private function get($len){ $str = ""; if($len <= 0){ return ""; } $offset = 0; while(!isset($str{$len - 1})){ if(isset($this->input{$offset})){ $str .= $this->input{$offset}; ++$offset; } } $this->input = (string) substr($this->input, $offset); return $str; } public function run(){ while($this->stop === false){ if(isset($this->input{5})){ //len 6 min $rID = \PocketMine\Utils\Utils::readInt($this->get(4)); switch(\PocketMine\Utils\Utils::readShort($this->get(2), false)){ case ASYNC_CURL_GET: $url = $this->get(\PocketMine\Utils\Utils::readShort($this->get(2), false)); $timeout = \PocketMine\Utils\Utils::readShort($this->get(2)); $res = (string) \PocketMine\Utils\Utils::getURL($url, $timeout); $this->lock(); $this->output .= \PocketMine\Utils\Utils::writeInt($rID) . \PocketMine\Utils\Utils::writeShort(ASYNC_CURL_GET) . \PocketMine\Utils\Utils::writeInt(strlen($res)) . $res; $this->unlock(); break; case ASYNC_CURL_POST: $url = $this->get(\PocketMine\Utils\Utils::readShort($this->get(2), false)); $timeout = \PocketMine\Utils\Utils::readShort($this->get(2)); $cnt = \PocketMine\Utils\Utils::readShort($this->get(2), false); $d = array(); for($c = 0; $c < $cnt; ++$c){ $key = $this->get(\PocketMine\Utils\Utils::readShort($this->get(2), false)); $d[$key] = $this->get(\PocketMine\Utils\Utils::readInt($this->get(4))); } $res = (string) \PocketMine\Utils\Utils::postURL($url, $d, $timeout); $this->lock(); $this->output .= \PocketMine\Utils\Utils::writeInt($rID) . \PocketMine\Utils\Utils::writeShort(ASYNC_CURL_POST) . \PocketMine\Utils\Utils::writeInt(strlen($res)) . $res; $this->unlock(); break; case ASYNC_FUNCTION: $function = $this->get(\PocketMine\Utils\Utils::readShort($this->get(2), false)); $params = unserialize($this->get(\PocketMine\Utils\Utils::readInt($this->get(4)))); $res = serialize(@call_user_func_array($function, $params)); $this->output .= \PocketMine\Utils\Utils::writeInt($rID) . \PocketMine\Utils\Utils::writeShort(ASYNC_FUNCTION) . \PocketMine\Utils\Utils::writeInt(strlen($res)) . $res; break; } } usleep(10000); } } } class Async extends \Thread{ public function __construct($method, $params = array()){ $this->method = $method; $this->params = $params; $this->result = null; $this->joined = false; } public function run(){ if(($this->result = call_user_func_array($this->method, $this->params))){ return true; } else{ return false; } } public static function call($method, $params = array()){ $thread = new Async($method, $params); if($thread->start()){ return $thread; } } public function __toString(){ if(!$this->joined){ $this->joined = true; $this->join(); } return (string) $this->result; } }