Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

As PHP version 5.5 is no longer supported by the community, we strongly recommend new apps use the PHP 7+ runtime.

Using the Modules API

The Modules API provides functions that return information about the current operating environment (module, version, and instance).

The Modules API also has functions that retrieve the address of a module, a version, or an instance. This allows an application to send requests from one instance to another, in both the development and production environments.

Add the following use statement to the top of your file:

use google\appengine\api\modules\ModulesService;

The following code sample shows how to get the module name and instance id for a request:

$module = ModulesService::getCurrentModuleName();
$instance = ModulesService::getCurrentInstanceId();

The instance ID of an automatic scaled module will be returned as a unique base64 encoded value, e.g. e4b565394caa.

You can communicate between modules in the same app by fetching the hostname of the target module:

use google\appengine\api\modules\ModulesService;
$url = 'http://' . ModulesService::getHostname('my-backend') . '/';
$result = file_get_contents($url);

You can also use the URL Fetch service.