https://github.com/kreait/gcp-metadata-php
Get the metadata from a Google Cloud Platform environment.
https://github.com/kreait/gcp-metadata-php
gce gcp google google-cloud google-cloud-engine google-cloud-platform
Last synced: 10 months ago
JSON representation
Get the metadata from a Google Cloud Platform environment.
- Host: GitHub
- URL: https://github.com/kreait/gcp-metadata-php
- Owner: kreait
- License: mit
- Created: 2018-07-27T10:12:25.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2022-06-21T22:21:57.000Z (over 3 years ago)
- Last Synced: 2025-04-09T19:18:05.471Z (10 months ago)
- Topics: gce, gcp, google, google-cloud, google-cloud-engine, google-cloud-platform
- Language: PHP
- Size: 39.1 KB
- Stars: 66
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# GCP Metadata
> Get the metadata from a Google Cloud Platform environment.
[](https://packagist.org/packages/kreait/gcp-metadata)
[]()
[](https://github.com/kreait/gcp-metadata-php/blob/main/LICENSE)
[](https://github.com/kreait/gcp-metadata-php/actions)
[](https://github.com/sponsors/jeromegamez)
```bash
$ composer install kreait/gcp-metadata
```
```php
use Kreait\GcpMetadata;
$metadata = new GcpMetadata();
```
#### Check if the metadata server is available
```php
$isAvailable = $metadata->isAvailable();
```
#### Get all available instance properties
```php
$data = $metadata->instance();
```
#### Get all available project properties
```php
$data = $metadata->project();
```
#### Access a specific property
```php
$data = $metadata->instance('hostname');
```
#### Wrap queries in a try/catch block if you don't check for availability
```php
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();
}
```