Avn*_*mon 10 php google-app-engine google-cloud-datastore
目前,我能够在部署代码后写入数据存储区,但是我无法使用本地运行的代码写入数据存储区模拟器,因为它会抛出ca-bundle错误.本地数据存储在localhost:8000中可见
use google\appengine\api\users\User;
use google\appengine\api\users\UserService;
use google\appengine\api\app_identity\AppIdentityService;
echo AppIdentityService::getApplicationId()."<br>";
echo AppIdentityService::getDefaultVersionHostname()."<br>";
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\ServiceBuilder;
$cloud = new ServiceBuilder([
'projectId' => AppIdentityService::getApplicationId(),
'keyFilePath'=>'review-9504000716d8.json'
]);
$datastore = $cloud->datastore();
# The kind for the new entity
$kind = 'Task';
# The name/ID for the new entity
$name = 'sampletask1';
# The Cloud Datastore key for the new entity
$taskKey = $datastore->key($kind, $name);
# Prepares the new entity
$task = $datastore->entity($taskKey, ['description' => 'Buy milk']);
# Saves the entity
$datastore->upsert($task);
Run Code Online (Sandbox Code Playgroud)
部署时,此代码运行时没有任何问题.但在当地引发:
Fatal error: Uncaught exception 'Google\Cloud\Exception\ServiceException' with message 'No system CA bundle could be found in any of the the common system locations. PHP versions earlier than 5.6 are not properly configured to use the system's CA bundle by default. In order to verify peer certificates, you will need to supply the path on disk to a certificate bundle to the 'verify' request option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not need a specific certificate bundle, then Mozilla provides a commonly used CA bundle which can be downloaded here (provided by the maintainer of cURL): https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP ini setting to point to the path to the file, allowing you to omit the 'verify' request option. See http://curl.haxx.se/docs/sslcerts.html for more information.' in D:\Google\php\appengine-php-guestbook-phase0-helloworld\appengine-php-guestbook-phase0-hellowo in D:\Google\php\appengine-php-guestbook-phase0-helloworld\appengine-php-guestbook-phase0-helloworld\vendor\google\cloud\src\RequestWrapper.php on line 219
Run Code Online (Sandbox Code Playgroud)
我没有设法让本地服务器甚至考虑php.ini文件,也没有设法将捆绑的php55升级到至少php56.
因此我实际上有两个问题:
API 使用 CA 证书文件进行身份验证,更具体地说,它们使用curl.cainfo.
现在您的服务器可能已经在php.ini中配置了此文件。您可以检查服务器文件。请记住,不同的环境(如 apache、cli)可能有不同的 ini 文件。
现在您可以复制该文件或创建您自己的权限文件
选项 1:
在 php.ini 中设置绝对路径
选项 2:
用于ini_set设置此配置。
选项 3:
尝试使用其他身份验证模式,我相信谷歌会有这种方式。
选项 4:
如您的问题本身所示。
如果您不需要特定的证书捆绑包,那么 Mozilla 提供了常用的 CA 捆绑包,可以在此处下载 https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt。一旦磁盘上有可用的 CA 捆绑包,您就可以将 PHP ini 设置中的“openssl.cafile”设置为指向该文件的路径,从而允许您省略“验证”请求选项