in src/ChannelRef.php [48:72]
public function getRealChannel($credentials)
{
// TODO(ddyihai): remove this check once the serialize handler for
// \Grpc\Channel is implemented(issue https://github.com/grpc/grpc/issues/15870).
if (!$this->has_deserialized->getData()) {
// $real_channel exists and is not created by the deserialization.
return $this->real_channel;
}
// If this ChannelRef is created by deserialization, $real_channel is invalid
// thus needs to be recreated becasue Grpc\Channel don't have serialize and
// deserialize handler.
// Since [target + augments + credentials] will be the same during the recreation,
// it will reuse the underline grpc channel in C extension without creating a
// new connection.
// 'credentials' in the array $opts will be unset during creating the channel.
if (!array_key_exists('credentials', $this->opts)) {
$this->opts['credentials'] = $credentials;
}
$real_channel = new \Grpc\Channel($this->target, $this->opts);
$this->real_channel = $real_channel;
// Set deserialization to false so it won't be recreated within the same script.
$this->has_deserialized->setData(0);
return $real_channel;
}