1. Go to this page and download the library: Download bigcommerce/grphp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bigcommerce / grphp example snippets
$config = new Grphp\Client\Config([
'hostname' => 'IP_OF_SERVER:PORT',
]);
$client = new Grphp\Client(Things\ThingsClient::class, $config);
$request = new Things\GetThingReq();
$request->setId(1234);
$resp = $client->call($request, 'GetThing');
$thing = $resp->getResponse(); // Things\Thing
echo $thing->id; // 1234
echo $resp->getStatusCode(); // 0 (these are gRPC status codes)
echo $resp->getStatusDetails(); // OK
$proxyConfig = new Grphp\Client\Strategy\H2Proxy\Config('http://0.0.0.0:3000', 15);
$proxyStrategyFactory = new Grphp\Client\Strategy\H2Proxy\StrategyFactory($proxyConfig);
$config = new Grphp\Client\Config([
'strategy' => $proxyStrategyFactory->build(),
]);
// Connect to Envoy at 127.0.0.1:19000
$envoyConfig = new Grphp\Client\Strategy\Envoy\Config('127.0.0.1', 19000, 2);
$envoyStrategyFactory = new Grphp\Client\Strategy\Envoy\StrategyFactory($envoyConfig);
$config = new Grphp\Client\Config([
'strategy' => $envoyStrategyFactory->build(),
]);
class MyProtoSerializer extends Grphp\Serializers\Errors\Base
{
public function deserialize($trailer)
{
$header = new \My\Proto\ErrorHeader();
$header->mergeFromString($trailer);
return $header;
}
}
$config = new Grphp\Client\Config([
'hostname' => 'IP_OF_SERVER:PORT',
'error_serializer' => new MyProtoSerializer(),
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.