2016-12-29 33 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'請求選項

相關問題