Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Metadata.
A library for accessing the Google Compute Engine (GCE) metadata.
The metadata is available from Google Compute Engine instances and
App Engine Managed VMs instances.
Example:
use Google\Cloud\Core\Compute\Metadata;
$metadata = new Metadata();
$projectId = $metadata->getProjectId();
// It is easy to get any metadata from a project.
$val = $metadata->getProjectMetadata($key);
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class Metadata (1.64.2)\n\nVersion latestkeyboard_arrow_down\n\n- [1.64.2 (latest)](/php/docs/reference/cloud-core/latest/Compute.Metadata)\n- [1.64.1](/php/docs/reference/cloud-core/1.64.1/Compute.Metadata)\n- [1.63.0](/php/docs/reference/cloud-core/1.63.0/Compute.Metadata)\n- [1.62.3](/php/docs/reference/cloud-core/1.62.3/Compute.Metadata)\n- [1.61.0](/php/docs/reference/cloud-core/1.61.0/Compute.Metadata)\n- [1.60.1](/php/docs/reference/cloud-core/1.60.1/Compute.Metadata)\n- [1.59.1](/php/docs/reference/cloud-core/1.59.1/Compute.Metadata)\n- [1.58.2](/php/docs/reference/cloud-core/1.58.2/Compute.Metadata)\n- [1.53.0](/php/docs/reference/cloud-core/1.53.0/Compute.Metadata)\n- [1.52.11](/php/docs/reference/cloud-core/1.52.11/Compute.Metadata)\n- [1.51.2](/php/docs/reference/cloud-core/1.51.2/Compute.Metadata)\n- [1.50.0](/php/docs/reference/cloud-core/1.50.0/Compute.Metadata)\n- [1.49.3](/php/docs/reference/cloud-core/1.49.3/Compute.Metadata)\n- [1.48.1](/php/docs/reference/cloud-core/1.48.1/Compute.Metadata) \nReference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class Metadata.\n\nA library for accessing the Google Compute Engine (GCE) metadata.\n\nThe metadata is available from Google Compute Engine instances and\nApp Engine Managed VMs instances.\n\nExample: \n\n use Google\\Cloud\\Core\\Compute\\Metadata;\n\n $metadata = new Metadata();\n $projectId = $metadata-\u003egetProjectId();\n\n // It is easy to get any metadata from a project.\n $val = $metadata-\u003egetProjectMetadata($key);\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Core \\\\ Compute\n\nMethods\n-------\n\n### __construct\n\n### setReader\n\nReplace the default reader implementation\n\n### get\n\nFetch a metadata item by its path\n\nExample: \n\n $projectId = $metadata-\u003eget('project/project-id');\n\n### getProjectId\n\nDetect and return the project ID\n\nExample: \n\n $projectId = $metadata-\u003egetProjectId();\n\n### getNumericProjectId\n\nDetect and return the numeric project ID\n\nExample: \n\n $projectId = $metadata-\u003egetNumericProjectId();\n\n### getProjectMetadata\n\nFetch an item from the project metadata\n\nExample: \n\n $foo = $metadata-\u003egetProjectMetadata('foo');\n\n### getInstanceMetadata\n\nFetch an item from the instance metadata\n\nExample: \n\n $foo = $metadata-\u003egetInstanceMetadata('foo');"]]