xref: /aosp_15_r20/external/grpc-grpc/src/php/tests/interop/xds_unary_call.php (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1<?php
2/*
3 *
4 * Copyright 2021 gRPC authors.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20$autoload_path = realpath(dirname(__FILE__).'/../../vendor/autoload.php');
21require_once $autoload_path;
22
23// This script is used to launch 1 single EmptyCall RPC, most likely
24// for the purpose of starting such RPC asynchronously away from the
25// main PHP xDS interop client src/php/tests/interop/xds_client.php.
26
27// This script is launched from src/php/bin/xds_manager.py. The result
28// of this RPC will be aggregated and reported back to the main runner
29// from there.
30
31$args = getopt('', ['server:', 'num:',
32                    'metadata:', 'timeout_sec:']);
33$TIMEOUT_US = 30 * 1e6; // 30 seconds
34
35$server_address = $args['server'];
36$num = $args['num'];
37
38$stub = new Grpc\Testing\TestServiceClient($server_address, [
39    'credentials' => Grpc\ChannelCredentials::createInsecure()
40]);
41
42$simple_request = new Grpc\Testing\SimpleRequest();
43
44$timeout = $args['timeout_sec'] ? $args['timeout_sec'] * 1e6 : $TIMEOUT_US;
45$metadata = [];
46if ($args['metadata']) {
47    $metadata = unserialize($args['metadata']);
48}
49
50$call = $stub->UnaryCall($simple_request,
51                         $metadata,
52                         ['timeout' => $timeout]);
53list($response, $status) = $call->wait();
54exit($status->code);
55