Syed Ausaf Hussain
Syed Ausaf Hussain

Reputation: 133

gRPC Request Timeout in Php

I am creating gRPC client in PHP through these steps

  1. I Defining the services in proto file.
  2. Then Generating client code
  3. Creating the client

Code of Creating a client object.

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);

now my question is How to set gRPC Request Timeout in these two methods

I am follow these links
https://grpc.io/docs/tutorials/basic/php.html
https://grpc.io/docs/guides/auth.html#php

Upvotes: 2

Views: 2799

Answers (1)

Zhouyihai Ding
Zhouyihai Ding

Reputation: 353

You can try set the 'timeout' in options when sending the request. eg: $client->UnaryCall($argument, $metadata, $options)

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

Upvotes: 1

Related Questions