DoraRPC\Client::multiAPI PHP Метод

multiAPI() публичный Метод

并发请求api,使用方法如 $params = array( "api_1117"=>array("name"=>"apiname1",“param”=>array("id"=>1117)), "api_2"=>array("name"=>"apiname2","param"=>array("id"=>2)), )
public multiAPI ( array $params, integer $mode = DoraConst::SW_MODE_WAITRESULT, integer $retry, string $ip = "", string $port = "" ) : mixed
$params array 提交参数 请指定key好方便区分对应结果,注意考虑到硬件资源有限并发请求不要超过50个
$mode integer
$retry integer 通讯错误时重试次数
$ip string 要连得ip地址,如果不指定从现有配置随机个
$port string 要连得port地址,如果不指定从现有配置找一个
Результат mixed 返回指定key结果
    public function multiAPI($params, $mode = DoraConst::SW_MODE_WAITRESULT, $retry = 0, $ip = "", $port = "")
    {
        //get guid
        $this->guid = $this->generateGuid();
        $packet = array('guid' => $this->guid, 'api' => $params);
        switch ($mode) {
            case DoraConst::SW_MODE_WAITRESULT:
                $packet["type"] = DoraConst::SW_MODE_WAITRESULT_MULTI;
                break;
            case DoraConst::SW_MODE_NORESULT:
                $packet["type"] = DoraConst::SW_MODE_NORESULT_MULTI;
                break;
            case DoraConst::SW_MODE_ASYNCRESULT:
                $packet["type"] = DoraConst::SW_MODE_ASYNCRESULT_MULTI;
                break;
            default:
                throw new \Exception("unknow mode have been set", 100099);
                break;
        }
        $sendData = Packet::packEncode($packet);
        $result = $this->doRequest($sendData, $packet["type"]);
        //retry when the send fail
        while ((!isset($result["code"]) || $result["code"] != 0) && $retry > 0) {
            $result = $this->doRequest($sendData, $packet["type"]);
            $retry--;
        }
        if ($this->guid != $result["guid"]) {
            return Packet::packFormat("guid wront please retry..", 100100, $result["data"]);
        }
        return $result;
    }