使用Google的PHP客户端库连接到BigTable时出错

时间:2019-08-03 15:05:40

标签: php google-app-engine google-cloud-platform google-cloud-bigtable

我已经在我的GC帐户中创建了一个BigTable实例,当我尝试使用Google的库连接到它时(这是来自Google文档的示例代码):

require 'vendor/autoload.php';

use Google\Cloud\Bigtable\BigtableClient;

/** Uncomment and populate these variables in your code */
$project_id = 'my_project_id';
$instance_id = 'table_instance';
$table_id = 'table_name';

// Connect to an existing table with an existing instance.
$dataClient = new BigtableClient([
    'projectId' => $project_id,
]);
$table = $dataClient->table($instance_id, $table_id);
$key = 'r1';
// Read a row from my-table using a row key
$row = $table->readRow($key);

$column_family_id = 'cf1';
$column_id = 'c1';
// Get the Value from the Row, using the column_family_id and column_id

$value = $row[$column_family_id][$column_id][0]['value'];

printf("Row key: %s\nData: %s\n", $key, $value);

我遇到错误:

Fatal error: Uncaught BadMethodCallException: Streaming calls are not supported while using the REST transport. in /srv/vendor/google/gax/src/Transport/HttpUnaryTransportTrait.php:119 Stack trace: #0 /srv/vendor/google/gax/src/Transport/HttpUnaryTransportTrait.php(63): Google\ApiCore\Transport\RestTransport->throwUnsupportedException() #1 /srv/vendor/google/gax/src/GapicClientTrait.php(479): Google\ApiCore\Transport\RestTransport->startServerStreamingCall(Object(Google\ApiCore\Call), Array) #2 /srv/vendor/google/gax/src/Middleware/CredentialsWrapperMiddleware.php(61): Google\Cloud\Bigtable\V2\Gapic\BigtableGapicClient->Google\ApiCore\{closure}(Object(Google\ApiCore\Call), Array) #3 /srv/vendor/google/gax/src/Middleware/FixedHeaderMiddleware.php(67): Google\ApiCore\Middleware\CredentialsWrapperMiddleware->__invoke(Object(Google\ApiCore\Call), Array) #4 /srv/vendor/google/gax/src/Middleware/RetryMiddleware.php(85): Google\ApiCore\Middleware\FixedHeaderMiddleware->__invoke(Object(Google\ApiCore\Call), Array) #5 /srv/vendor/google/gax/src/Middleware/OptionsFilterMiddleware.php(64): Google\ApiCore\Middleware\RetryMiddleware->__invoke(Object(Google\ApiCore\Call), Array) #6 /srv/vendor/google/gax/src/GapicClientTrait.php(462): Google\ApiCore\Middleware\OptionsFilterMiddleware->__invoke(Object(Google\ApiCore\Call), Array) #7 /srv/vendor/google/cloud-bigtable/src/V2/Gapic/BigtableGapicClient.php(357): Google\Cloud\Bigtable\V2\Gapic\BigtableGapicClient->startCall('ReadRows', 'Google\\Cloud\\Bi...', Array, Object(Google\Cloud\Bigtable\V2\ReadRowsRequest), 3) #8 [internal function]: Google\Cloud\Bigtable\V2\Gapic\BigtableGapicClient->readRows('projects/project...', Array) #9 /srv/vendor/google/cloud-core/src/ExponentialBackoff.php(80): call_user_func_array(Array, Array) #10 /srv/vendor/google/cloud-bigtable/src/ResumableStream.php(96): Google\Cloud\Core\ExponentialBackoff->execute(Array, Array) #11 /srv/vendor/google/cloud-bigtable/src/ChunkFormatter.php(168): Google\Cloud\Bigtable\ResumableStream->readAll() #12 [internal function]: Google\Cloud\Bigtable\ChunkFormatter->readAll() #13 /srv/vendor/google/cloud-bigtable/src/Table.php(331): Generator->current() #14 /srv/index.php(24): Google\Cloud\Bigtable\Table->readRow('r1') #15 {main} thrown in /srv/vendor/google/gax/src/Transport/HttpUnaryTransportTrait.php on line 119

有帮助吗?

1 个答案:

答案 0 :(得分:0)

好,我知道了。

对于那些面临相同问题的人: 在您的php.ini文件中创建/添加一行: extension=grpc.so

php.ini应该与app.yaml相同目录