IIS环境无法连接Google Firestore,报Empty address list错误(错误码14)
IIS环境下PHP调用Firestore报empty address list错误
在Windows系统的IIS环境中运行PHP 8.1(已安装grpc与sodium扩展),持有Google Firebase凭据文件,仅需读取名为"info"的集合。同一机器上的Apache(Laragon)环境运行相同代码可正常工作,但IIS返回错误:
{"error": "{
"message": "empty address list: ",
"code": 14,
"status": "UNAVAILABLE",
"details": []
}"}
已尝试PHP 8.1、8.2及8.3版本,均出现相同错误。测试用函数代码如下:
public function testFirestore() { $credentialsPath = base_path(env('FIREBASE_CREDENTIALS')); putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentialsPath); putenv('GRPC_VERBOSITY=DEBUG'); putenv('GRPC_TRACE=all'); try { // Log the credentials path and environment variable Log::info('GOOGLE_APPLICATION_CREDENTIALS: ' . getenv('GOOGLE_APPLICATION_CREDENTIALS')); Log::info('Service account file exists: ' . (file_exists($credentialsPath) ? 'yes' : 'no')); Log::info('GRPC_VERBOSITY: ' . getenv('GRPC_VERBOSITY')); Log::info('GRPC_TRACE: ' . getenv('GRPC_TRACE')); $firestore = new FirestoreClient([ 'projectId' => '[projectid]', ]); $collection = $firestore->collection('info'); $documents = $collection->documents(); $result = []; foreach ($documents as $document) { $result[] = [ 'id' => $document->id(), 'data' => $document->data() ]; } return response()->json($result); } catch (\Exception $e) { Log::error('Firestore error: ' . $e->getMessage()); return response()->json(['error' => $e->getMessage()], 500); } }
如需排查,可提供php.ini文件。
内容的提问来源于stack exchange,提问作者MiloTheGreat
相关产品推荐
相关产品推荐

