2016-12-29 71 views
10

目前我能够写入数据存储一旦我部署我的代码,但我不能写入数据存储模拟器与本地运行的代码,因为它会抛出一个CA包错误。本地数据存储在本地主机上可见:8000使用本地谷歌数据存储与dev_appserver.pyp

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); 

此代码在部署时运行时没有任何问题。但本地抛出:

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 

我没让本地服务器甚至考虑php.ini文件我也没有设法捆绑php55至少升级到php56。

因此,我居然有2个问题:

  1. 如何正确连接从本地实例(dev_appserver.py)在Windows谷歌的远程数据存储?
  2. 如何正确连接从本地即时到本地模拟数据存储,以便我可以查看localhost:8000上的数据?
+0

PHP的文档是可悲的。您是否可以让您的dev_appserver.py实例与数据存储模拟器进行通信? –

+0

不,但有趣的事实,使用https://github.com/tomwalder/php-gds后,我停止了错误。 –

回答

1

API正在使用CA证书文件进行身份验证,更具体地说,它们使用的是curl.cainfo

现在你的服务器可能已经在配置文件php.ini。您可以检入服务器文件。请记住,不同的环境可能会有不同的ini文件,如apache,cli。

现在,您可以复制该文件或文件Create your own authority file

选项1:在php.ini

选项2
设置绝对路径:
使用ini_set设置此配置。

选项3:
尝试一些其他认证模式,我相信谷歌会有这样的。

选项4:
正如你的问题本身给出的。

如果您不需要特定的证书捆绑,然后Mozilla的提供了常用的CA束可以在这里 https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt下载。一旦你在磁盘上有一个CA软件包,你可以设置'openssl.cafile'PHP ini设置指向该文件的路径,允许你省略'verify'请求选项

相关问题