google/cloud-spanner
Idiomatic PHP client for Google Cloud Spanner, a fully managed relational database with global scale, strong transactional consistency, SQL support, and high availability. Install via Composer, authenticate, and run queries; supports gRPC and multiplexed sessions.
// app/Providers/AppServiceProvider.php
use Google\Cloud\Spanner\SpannerClient;
use Illuminate\Support\Facades\DB;
DB::extend('spanner', function ($config) {
$spanner = new SpannerClient();
$db = $spanner->instance($config['instance'])->database($config['database']);
return new SpannerConnection($db);
});
? vs. named params) may require adapter layers.pecl install grpc)..env can store GOOGLE_APPLICATION_CREDENTIALS.| Risk Area | Mitigation Strategy |
|---|---|
| Cold Starts | Use connection pooling (multiplexed sessions) and keepalive (120s default). |
| Schema Migrations | Leverage Spanner’s DDL (e.g., ALTER TABLE) via Laravel Migrations. |
| Cost Overruns | Monitor node allocation (Spanner charges by CPU/memory) and query patterns. |
| Vendor Lock-in | Abstract Spanner-specific logic behind interfaces (e.g., SpannerRepository). |
| Debugging Complexity | Use Cloud Logging middleware and request IDs for tracing. |
pg_trgm).Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
// Spanner-specific: Add INTERLEAVE for hot/cold data
$table->interleave('orders');
});
| Laravel Feature | Spanner Support | Workaround |
|---|---|---|
| Eloquent Relationships | ✅ (via custom driver) | Implement SpannerHasMany, etc. |
| Migrations | ✅ (DDL) | Use raw SQL or custom migration builder. |
| Queues | ❌ | Use Pub/Sub + Cloud Tasks as fallback. |
| Caching | ✅ (PSR-6 cache) | Configure cacheItemPool in SpannerClient. |
| Redis | ❌ | Use Memorystore for session caching. |
roles/spanner.databaseUser).google/cloud-spanner to composer.json.Technical Evaluation).Google\Cloud\Spanner\Mock\SpannerMock).$spanner = new SpannerClient([
'logging' => [
'handler' => new Google\Cloud\Core\Logging\CloudLoggingHandler(),
],
]);
grpc.timeout_ms in client config.spanner.googleapis.com/api/requests).How can I help you explore Laravel packages today?