From 7b3977e9f13721a47d126a0a2399ca177f934d89 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Tue, 7 Mar 2023 01:00:10 +0100 Subject: [PATCH] Use correct namespace for checking if the isDefaultRootsPemSet method exists. (#31580) The `method_exists` function requires a fully qualified class name to be sent to check if a method exists. The current class was missing the namespace, which means the function always returns `false`. In our application this caused the credentials to be loaded many times over, which ate up some CPU. This bug fix ensures that this is only run once per request. --- src/php/lib/Grpc/BaseStub.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index 9697c716c86..f56c96ef8d5 100644 --- a/src/php/lib/Grpc/BaseStub.php +++ b/src/php/lib/Grpc/BaseStub.php @@ -43,7 +43,7 @@ class BaseStub */ public function __construct($hostname, $opts, $channel = null) { - if (!method_exists('ChannelCredentials', 'isDefaultRootsPemSet') || + if (!method_exists('Grpc\ChannelCredentials', 'isDefaultRootsPemSet') || !ChannelCredentials::isDefaultRootsPemSet()) { $ssl_roots = file_get_contents( dirname(__FILE__).'/../../../../etc/roots.pem'