kreait / gcp-metadata
Get the metadata from a Google Cloud Platform environment.
Fund package maintenance!
jeromegamez
Installs: 4 443 023
Dependents: 1
Suggesters: 0
Security: 0
Stars: 66
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: ^7.4|^8.0
- guzzlehttp/guzzle: ^6.5.8|^7.4.5
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.5.20
README
Get the metadata from a Google Cloud Platform environment.
$ composer install kreait/gcp-metadata
use Kreait\GcpMetadata; $metadata = new GcpMetadata();
Check if the metadata server is available
$isAvailable = $metadata->isAvailable();
Get all available instance properties
$data = $metadata->instance();
Get all available project properties
$data = $metadata->project();
Access a specific property
$data = $metadata->instance('hostname');
Wrap queries in a try/catch block if you don't check for availability
use Kreait\GcpMetadata; $metadata = new GcpMetadata(); if ($metadata->isAvailable()) { echo $metadata->instance('hostname'); } try { echo $metadata->instance('hostname'); } catch (GcpMetadata\Error $e) { echo $e->getMessage(); }