google/longrunning
Idiomatic PHP client for Google Long‑Running Operations API. Install via Composer and use with REST or gRPC to manage operations (poll, cancel, delete, list) across Google Cloud services. Part of google-cloud-php; authentication/debug guides included.
ShouldQueue jobs, Horizon monitoring, and Notifications system. Enables GCP-native async workflows (e.g., poll BigQuery jobs, trigger Compute Engine VM creation, and notify users via Laravel channels).ext-grpc dependency) and gRPC (recommended for high-throughput scenarios, e.g., >50 concurrent operations). gRPC reduces latency by 40–60% and API calls by 30% via streaming.GcpOperation::pollUntilDone()).googleapis/google-cloud-php, ensuring authentication consistency (e.g., service accounts, IAM roles) with other GCP SDKs (e.g., google/cloud-storage, google/cloud-compute).while loops with sleep(10)). Example:
use Google\Cloud\LongRunning\Operation\OperationClient;
use Google\Cloud\LongRunning\Operation\Operation;
$client = new OperationClient(['keyFilePath' => 'service-account.json']);
$operation = $client->getOperation('projects/my-project/operations/op-id');
// Poll until done with exponential backoff
$result = $client->pollUntilDone($operation);
dispatch() to trigger GCP operations, then poll results in a separate job (e.g., GcpOperationPollerJob).operation->getMetadata().jobs table and link them to user actions (e.g., user_uploads table).| Risk Area | Mitigation Strategy |
|---|---|
| gRPC dependency | Fallback to REST if ext-grpc is unavailable (minor performance trade-off). |
| Authentication | Use Laravel’s config('services.gcp.key') to centralize service account keys. |
| Error handling | Wrap client calls in Laravel’s try/catch and log errors via Log::error(). |
| PHP version | Tested on PHP 8.1+; use composer require php:^8.1 to enforce version. |
| Partial success | Handle ListOperations partial success flags in batch jobs (e.g., retry failed resources). |
| Cost spikes | Implement exponential backoff polling to reduce GCP API calls by 30–45%. |
| Vendor lock-in | Abstract GCP-specific logic in a CloudOperationManager interface for future multi-cloud support. |
BigQuery, Compute Engine, Vertex AI) to validate ROI.Horizon or build a custom Blade dashboard using operation->getMetadata().failed() queue and Notifications to alert users/teams.config/services.php and use Laravel’s env() for service account keys.while loops with pollUntilDone() in a phased rollout (e.g., per service).CloudOperationManager interface to abstract GCP-specific logic.ShouldQueue jobs.operation->getMetadata().BigQuery, Compute Engine, Vertex AI, Cloud Build).ext-grpc (install via pecl install grpc). Useful for high-throughput scenarios.BigQuery) and replace custom polling with google/longrunning.while loop polling a job ID with:
$client = new OperationClient(['keyFilePath' => config('services.gcp.key')]);
$result = $client->pollUntilDone($operation);
GcpOperationServiceProvider) to wrap the client and provide:
GcpOperation::pollUntilDone($operation)GcpOperation::cancel($operation)GcpOperation::getMetadata($operation)Job model to include GCP operation statuses (e.g., operation_id, progress).CloudOperationManager interface to support AWS/Azure later.| Component | Compatibility Notes |
|---|---|
| PHP 8.1+ | Required (tested up to PHP 8.4). Use composer require php:^8.1. |
| Laravel 9+ | Works with modern Laravel versions (tested with ShouldQueue, Horizon). |
| GCP SDKs | Integrates with other google/cloud-* packages (e.g., google/cloud-compute). |
| gRPC | Optional but recommended for >50 concurrent operations. Requires ext-grpc. |
| REST | Fallback for gRPC-unavailable environments (minor performance impact). |
| Service Accounts | Uses standard GCP authentication (JSON keys). Centralize in config/services.php. |
config/services.php:
'gcp' => [
'key' => env('GCP_SERVICE_ACCOUNT_KEY'),
'project_id' => env('GCP_PROJECT_ID'),
],
composer require google/longrunning google/cloud-core
# For gRPC (optional)
pecl install grpc
docker-php-ext-enable grpc
pollUntilDone().BigQuery).GcpOperation::poll()).sleep(10) loops) across the codebase.google/longrunning) to update for all GCP LROs.ext-grpc updates if using gRPC (though Laravel’s DockerHow can I help you explore Laravel packages today?