From 24722e3c9ae706f7f222871b27207b181aea6eb1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 23 Feb 2014 13:39:34 +0100 Subject: [PATCH] Added #1196 async function queuing Type ID: ASYNC_FUNCTION Params: array("function" => $functionName, "arguments" => array $argumentArray) --- src/MainServer.php | 10 ++++++++++ src/utils/pthreads.php | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/MainServer.php b/src/MainServer.php index 163a797f4..9be40b243 100644 --- a/src/MainServer.php +++ b/src/MainServer.php @@ -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])){ diff --git a/src/utils/pthreads.php b/src/utils/pthreads.php index d4a3faaf0..38a8d6619 100644 --- a/src/utils/pthreads.php +++ b/src/utils/pthreads.php @@ -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);