Example #1
0
                case ProtocolCached_Request_RequestType::SET:
                    echo sprintf("# set operation: %d, %d\n", $request->getSet()->getKey(), strlen($request->getSet()->getValue()));
                    $store->set($request->getSet()->getKey(), $request->getSet()->getValue());
                    var_dump($store);
                    var_dump($request);
                    break;
                case ProtocolCached_Request_RequestType::GET:
                    $result = $store->get($request->getGet()->getKey());
                    break;
            }
        } catch (ProtocolBuffers\InvalidProtocoBufferException $e) {
            echo $e->getMessage();
        }
        if ($result) {
            $response = new ProtocolCached_Response();
            $response->setType(ProtocolCached_Response_ResponseType::GET);
            $payload = new ProtocolCached_GetResponse();
            $payload->setValue($result);
            $response->setGet($payload);
            uv_write($socket, $response->serializeToString(), function ($socket, $stat) {
                echo "# Connection closed\n";
                uv_close($socket);
            });
        } else {
            echo "# Connection closed\n";
            uv_close($socket);
        }
    });
});
$timer = uv_timer_init();
$stat = array();