Php中的gRPC请求超时

时间:2019-02-22 10:07:53

标签: php grpc

我将通过以下步骤在PHP中创建gRPC客户端

  1. 我在原始文件中定义服务。
  2. 然后生成客户端代码
  3. 创建客户

创建客户端对象的代码。

simple or authorization method
$client = new Routeguide\RouteGuideClient('localhost:50051', [
    'credentials' => Grpc\ChannelCredentials::createInsecure(),
]);

Authenticate with Google
function updateAuthMetadataCallback($context)
{
    $auth_credentials = ApplicationDefaultCredentials::getCredentials();
    return $auth_credentials->updateMetadata($metadata = [], $context->service_url);
}
$channel_credentials = Grpc\ChannelCredentials::createComposite(
    Grpc\ChannelCredentials::createSsl(file_get_contents('roots.pem')),
    Grpc\CallCredentials::createFromPlugin('updateAuthMetadataCallback')
);
$opts = [
  'credentials' => $channel_credentials
];
$client = new helloworld\GreeterClient('greeter.googleapis.com', $opts);

现在我的问题是如何在这两种方法中设置gRPC请求超时

我正在关注这些链接
https://grpc.io/docs/tutorials/basic/php.html
https://grpc.io/docs/guides/auth.html#php

1 个答案:

答案 0 :(得分:1)

您可以在发送请求时尝试在选项中设置“超时”。例如:$ client-> UnaryCall($ argument,$ metadata,$ options)

https://github.com/grpc/grpc/blob/618a3f561d4a93f263cca23abad086ed8f4d5e86/src/php/lib/Grpc/AbstractCall.php#L51-L59