PHP code example of kreait / gcp-metadata

1. Go to this page and download the library: Download kreait/gcp-metadata library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kreait / gcp-metadata example snippets


use Kreait\GcpMetadata;

$metadata = new GcpMetadata();

$isAvailable = $metadata->isAvailable();

$data = $metadata->instance();

$data = $metadata->project();

$data = $metadata->instance('hostname');

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();
}