google / cloud-spanner
Cloud Spanner Client for PHP
Requires
- php: ^8.0
- ext-grpc: *
- google/cloud-core: ^1.57
- google/gax: ^1.36.0
Requires (Dev)
- erusev/parsedown: ^1.6
- google/cloud-pubsub: ^2.0
- phpdocumentor/reflection: ^5.3.3||^6.0
- phpdocumentor/reflection-docblock: ^5.3
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: 2.*
Suggests
- ext-protobuf: Provides a significant increase in throughput over the pure PHP protobuf implementation. See https://cloud.google.com/php/grpc for installation instructions.
- brick/math: Perform arithmetic on NUMERIC values.
- dev-main
- v1.91.0
- v1.90.0
- v1.89.0
- v1.88.0
- v1.87.0
- v1.86.0
- v1.85.0
- v1.84.0
- v1.83.0
- v1.82.0
- v1.81.0
- v1.80.0
- v1.79.0
- v1.78.0
- v1.77.0
- v1.76.1
- v1.76.0
- v1.75.2
- v1.75.1
- v1.75.0
- v1.74.0
- v1.73.0
- v1.72.0
- v1.71.0
- v1.70.0
- v1.69.0
- v1.68.0
- v1.67.0
- v1.65.0
- v1.64.0
- v1.63.2
- v1.63.1
- v1.63.0
- v1.62.1
- v1.62.0
- v1.61.0
- v1.60.0
- v1.59.0
- v1.58.4
- v1.58.3
- v1.58.2
- v1.58.1
- v1.58.0
- v1.57.0
- v1.56.0
- v1.55.0
- v1.54.2
- v1.54.1
- v1.54.0
- v1.53.0
- v1.52.0
- v1.51.2
- v1.51.1
- v1.51.0
- v1.50.0
- v1.49.2
- v1.49.1
- v1.49.0
- v1.48.2
- v1.48.1
- v1.48.0
- v1.47.0
- v1.46.3
- v1.46.2
- v1.46.1
- v1.46.0
- v1.45.0
- v1.44.0
- v1.43.0
- v1.42.0
- v1.41.0
- v1.40.0
- v1.39.0
- v1.38.0
- v1.37.0
- v1.36.0
- v1.35.0
- v1.34.0
- v1.33.0
- v1.32.3
- v1.32.2
- v1.32.1
- v1.32.0
- v1.31.0
- v1.30.1
- v1.30.0
- v1.29.2
- v1.29.1
- v1.29.0
- v1.28.0
- v1.27.1
- v1.27.0
- v1.26.0
- v1.25.0
- v1.24.1
- v1.24.0
- v1.23.0
- v1.22.0
- v1.21.0
- v1.20.0
- v1.19.0
- v1.18.0
- v1.17.0
- v1.16.1
- v1.16.0
- v1.15.6
- v1.15.5
- v1.15.4
- v1.15.3
- v1.15.2
- v1.15.1
- v1.15.0
- v1.14.0
- v1.13.0
- v1.12.0
- v1.11.7
- v1.11.6
- v1.11.5
- v1.11.4
- v1.11.3
- v1.11.2
- v1.11.1
- v1.11.0
- v1.10.1
- v1.10.0
- v1.9.0
- v1.8.0
- v1.7.0
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v0.11.0
- v0.10.0
- v0.9.1
- v0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2024-12-12 23:19:00 UTC
README
Idiomatic PHP client for Cloud Spanner.
NOTE: This repository is part of Google Cloud PHP. Any support requests, bug reports, or development contributions should be directed to that project.
A fully managed, mission-critical, relational database service that offers transactional consistency at global scale, schemas, SQL (ANSI 2011 with extensions), and automatic, synchronous replication for high availability.
Installation
To begin, install the preferred dependency manager for PHP, Composer.
Now install this component:
$ composer require google/cloud-spanner
This component requires the gRPC extension. Please see our gRPC installation guide for more information on how to configure the extension.
Authentication
Please see our Authentication guide for more information on authenticating your client. Once authenticated, you'll be ready to start making requests.
Sample
require 'vendor/autoload.php'; use Google\Cloud\Spanner\SpannerClient; $spanner = new SpannerClient(); $db = $spanner->connect('my-instance', 'my-database'); $userQuery = $db->execute('SELECT * FROM Users WHERE id = @id', [ 'parameters' => [ 'id' => $userId ] ]); $user = $userQuery->rows()->current(); echo 'Hello ' . $user['firstName'];
Session warmup
To issue a query against the Spanner service, the client library needs to request a session id from the server under the cover. This API call will add significant latency to your program. The Spanner client library provides a handy way to alleviate this problem by having a cached session pool.
For more details, see: https://github.com/googleapis/google-cloud-php/blob/main/Spanner/src/Session/CacheSessionPool.php#L30
The following example shows how to use the CacheSessionPool
with SysVCacheItemPool
as well as how to configure a proper cache for authentication:
require __DIR__ . '/vendor/autoload.php'; use Google\Cloud\Spanner\SpannerClient; use Google\Cloud\Spanner\Session\CacheSessionPool; use Google\Auth\Cache\SysVCacheItemPool; $authCache = new SysVCacheItemPool(); $sessionCache = new SysVCacheItemPool([ // Use a different project identifier for ftok than the default 'proj' => 'B', // We highly recommend using 250kb as it should safely contain the default // 500 maximum sessions the pool can handle. Please modify this value // accordingly depending on the number of maximum sessions you would like // for the pool to handle. 'memsize' => 250000 ]); $spanner = new SpannerClient([ 'authCache' => $authCache ]); $sessionPool = new CacheSessionPool( $sessionCache, [ 'minSessions' => 10, 'maxSessions' => 10 // Here it will create 10 sessions under the cover. ] ); $database = $spanner->connect( 'my-instance', 'my-db', [ 'sessionPool' => $sessionPool ] ); // `warmup` will actually create the sessions for the first time. $sessionPool->warmup();
By using a cache implementation like SysVCacheItemPool
, you can share the cached sessions among multiple processes, so that for example, you can warmup the session upon the server startup, then all the other PHP processes will benefit from the warmed up sessions.
Debugging
Please see our Debugging guide for more information about the debugging tools.
Version
This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in any minor or patch releases. We will address issues and requests with the highest priority.
Next Steps
- Understand the official documentation.
- Take a look at in-depth usage samples.