GoogleCloudPlatform / php-docs-samples

A collection of samples that demonstrate how to call Google Cloud services from PHP.
http://cloud.google.com/php
Apache License 2.0
962 stars 1.03k forks source link

Spanner - Undefined constant 'Grpc\STATUS_UNKNOWN' #466

Closed semmiverian closed 5 years ago

semmiverian commented 7 years ago

Good afternoon guys. i've been trying to fetch data from spanner with my laravel php application, but i always get this error

Undefined constant 'Grpc\STATUS_UNKNOWN'

My Code is as simple as this

 $spanner = new SpannerClient(['projectId' => 'kofera-technology']);

 $instance = $spanner->instance('datastream');

 $database = $instance->database('datastream');

 $database->runTransaction(function (Transaction $t) use ($request, $today, $startOfMonth) {

  $isoStringToday = $today->format(DateTime::ISO8601);

  $isoStringStartOfMonth = $startOfMonth->format(DateTime::ISO8601);

  $ownerId = $request->owner_id;

   $query = "SELECT * FROM kofera_billing_history WHERE kofera_id=$ownerId AND timestamp <= 

 $isoStringToday  and timestamp > $isoStringStartOfMonth";

  $rows = $t->execute($query)->rows();

  dd($rows);
});

i've already installed grpc package from pecl and adding the extension to the php.ini file.

is there anyway i could verify my grpc is working? i thought maybe that could be a problem too

and this is my composer.json

"require": { "php": ">=7.0", "laravel/lumen-framework": "5.5.*", "vlucas/phpdotenv": "~2.2", "firebase/php-jwt": "^5.0", "tymon/jwt-auth": "^1.0@dev", "predis/predis": "^1.1", "illuminate/redis": "^5.5", "weblee/mandrill": "dev-master", "vluzrmos/tinker": "^1.3", "ramsey/uuid": "^3.7", "chartmogul/chartmogul-php": "^1.1", "kitetail/zttp": "^0.3.0", "google/cloud-spanner": "^0.7.0" },

--- edit ---

i already make sure that i've already installed grpc with this code

get_loaded_extensions() [restof it, "grpc"]

Thanks for your help

regards semmi verian

bshaffer commented 5 years ago

Hello! Yes, that error happens if the grpc extension isn't enabled. I am not sure why this is happening if your get_loaded_extensions() contains "grpc". It is possible you have an older version of the extension. I would advise trying to install it again.

I tested this on my machine and received the following:

$ php -i | grep grpc
Additional .ini files parsed => /usr/local/etc/php/7.1/conf.d/ext-grpc.ini,
grpc
grpc support => enabled
grpc module version => 1.17.0
$ php -r "var_dump(Grpc\STATUS_UNKNOWN);"
int(2)