diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index af1372878df..add896ac517 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -100,6 +100,17 @@ PHP_METHOD(ChannelCredentials, setDefaultRootsPem) { memcpy(default_pem_root_certs, pem_roots, pem_roots_length + 1); } +/** + * if default roots pem is set + * @return TRUE/FALSE + */ +PHP_METHOD(ChannelCredentials, isDefaultRootsPemSet) { + if (default_pem_root_certs) { + RETURN_TRUE; + } + RETURN_FALSE; +} + /** * Create a default channel credentials object. * @return ChannelCredentials The new default channel credentials object @@ -214,6 +225,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setDefaultRootsPem, 0, 0, 1) ZEND_ARG_INFO(0, pem_roots) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_isDefaultRootsPemSet, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_createDefault, 0, 0, 0) ZEND_END_ARG_INFO() @@ -234,6 +248,8 @@ ZEND_END_ARG_INFO() static zend_function_entry channel_credentials_methods[] = { PHP_ME(ChannelCredentials, setDefaultRootsPem, arginfo_setDefaultRootsPem, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(ChannelCredentials, isDefaultRootsPemSet, arginfo_isDefaultRootsPemSet, + ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(ChannelCredentials, createDefault, arginfo_createDefault, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(ChannelCredentials, createSsl, arginfo_createSsl, diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index f33dbd4a80c..a154f6b41f0 100644 --- a/src/php/lib/Grpc/BaseStub.php +++ b/src/php/lib/Grpc/BaseStub.php @@ -43,10 +43,12 @@ class BaseStub */ public function __construct($hostname, $opts, $channel = null) { - $ssl_roots = file_get_contents( - dirname(__FILE__).'/../../../../etc/roots.pem' - ); - ChannelCredentials::setDefaultRootsPem($ssl_roots); + if (!ChannelCredentials::isDefaultRootsPemSet()) { + $ssl_roots = file_get_contents( + dirname(__FILE__).'/../../../../etc/roots.pem' + ); + ChannelCredentials::setDefaultRootsPem($ssl_roots); + } $this->hostname = $hostname; $this->update_metadata = null;