Added #1196 async function queuing

Type ID: ASYNC_FUNCTION
Params: array("function" => $functionName, "arguments" => array
$argumentArray)
This commit is contained in:
Shoghi Cervantes 2014-02-23 13:39:34 +01:00
parent 13274ebefa
commit 24722e3c9a
2 changed files with 17 additions and 0 deletions

View File

@ -228,6 +228,10 @@ class MainServer{
$d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value;
}
break;
case ASYNC_FUNCTION:
$params = serialize($data["arguments"]);
$d .= Utils::writeShort(strlen($data["function"])).$data["function"] . Utils::writeInt(strlen($params)) . $params;
break;
default:
return false;
}
@ -256,6 +260,12 @@ class MainServer{
$data["result"] = substr($this->asyncThread->output, $offset, $len);
$offset += $len;
break;
case ASYNC_FUNCTION:
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
$offset += 4;
$data["result"] = unserialize(substr($this->asyncThread->output, $offset, $len));
$offset += $len;
break;
}
$this->asyncThread->output = substr($this->asyncThread->output, $offset);
if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){

View File

@ -21,6 +21,7 @@
define("ASYNC_CURL_GET", 1);
define("ASYNC_CURL_POST", 2);
define("ASYNC_FUNCTION", 3);
class StackableArray extends Stackable{
public function __construct(){
@ -94,6 +95,12 @@ class AsyncMultipleQueue extends Thread{
$this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_CURL_POST).Utils::writeInt(strlen($res)).$res;
$this->unlock();
break;
case ASYNC_FUNCTION:
$function = $this->get(Utils::readShort($this->get(2), false));
$params = unserialize($this->get(Utils::readInt($this->get(4))));
$res = serialize(@call_user_func_array($function, $params));
$this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_FUNCTION).Utils::writeInt(strlen($res)).$res;
break;
}
}
usleep(10000);