google / cloud-spanner
PHP版云Spanner客户端
Requires
- php: ^8.0
- ext-grpc: *
- google/cloud-core: ^1.52.7
- google/gax: ^1.34.0
Requires (Dev)
- erusev/parsedown: ^1.6
- google/cloud-pubsub: ^2.0
- phpdocumentor/reflection: ^5.3.3
- 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.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-08-26 19:05:07 UTC
README
用于 Cloud Spanner 的PHP客户端。
注意: 此存储库是 Google Cloud PHP 的一部分。任何支持请求、错误报告或开发贡献应直接提交给该项目。
一个完全托管、关键任务的关系型数据库服务,提供全局规模的事务一致性、模式、SQL(ANSI 2011及扩展)和自动、同步复制以提高可用性。
安装
首先,安装PHP首选依赖关系管理器 Composer。
现在安装此组件
$ composer require google/cloud-spanner
此组件需要gRPC扩展。请参阅我们的 gRPC安装指南 获取有关配置扩展的更多信息。
身份验证
请参阅我们的 身份验证指南 获取有关身份验证客户端的更多信息。一旦认证完成,您就可以开始发送请求。
示例
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'];
会话预热
要对Spanner服务发出查询,客户端库需要在服务器幕后请求一个会话ID。此API调用将显著增加您程序的延迟。Spanner客户端库通过提供一个缓存的会话池来提供一种方便的方式来减轻这个问题。
更多详细信息,请参阅: https://github.com/googleapis/google-cloud-php/blob/main/Spanner/src/Session/CacheSessionPool.php#L30
以下示例展示了如何使用 CacheSessionPool
与 SysVCacheItemPool
,以及如何配置适当的缓存以进行身份验证
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();
通过使用类似 SysVCacheItemPool
的缓存实现,您可以在多个进程之间共享缓存的会话,例如,在服务器启动时预热会话,然后所有其他PHP进程都将从预热好的会话中受益。
版本
此组件被视为GA(通常可用)。因此,它不会在任何次要或修补版本中引入不兼容的更改。我们将以最高优先级处理问题和请求。