Exemplo n.º 1
0
        case "set":
            return ProtocolCached_Request_RequestType::SET;
            break;
        case "get":
            return ProtocolCached_Request_RequestType::GET;
            break;
        default:
            throw new Exception("GET or SET only");
    }
}
$c = uv_tcp_init();
uv_tcp_connect6($c, uv_ip6_addr('::1', 9999), function ($client, $stat) {
    if ($stat == 0) {
        $request = new ProtocolCached_Request();
        $type = getRequestType($_SERVER['argv'][1]);
        $request->setType($type);
        if ($type == ProtocolCached_Request_RequestType::SET) {
            $set = new ProtocolCached_SetRequest();
            $set->setKey($_SERVER['argv'][2]);
            $set->setValue($_SERVER['argv'][3]);
            $request->setSet($set);
        } else {
            if ($type == ProtocolCached_Request_RequestType::GET) {
                $set = new ProtocolCached_GetRequest();
                $set->setKey($_SERVER['argv'][2]);
                $request->setGet($set);
            }
        }
        uv_write($client, $request->serializeToString(), function ($socket, $stat) use($type) {
            if ($type == ProtocolCached_Request_RequestType::GET) {
                uv_read_start($socket, function ($socket, $nread, $buffer) use($type) {