我将通过以下步骤在PHP中创建gRPC客户端
创建客户端对象的代码。
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
答案 0 :(得分:1)
您可以在发送请求时尝试在选项中设置“超时”。例如:$ client-> UnaryCall($ argument,$ metadata,$ options)