Utiliser l'API Modules
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
L'API Modules propose des fonctions qui renvoient des informations sur l'environnement d'exploitation actuel (module, version et instance).
Elle comporte également des fonctions qui servent à récupérer l'adresse d'un module, d'une version ou d'une instance. Cela permet à une application d'envoyer des requêtes d'une instance à une autre dans les environnements de développement et de production.
Ajoutez l'instruction d'utilisation suivante en haut de votre fichier :
L'exemple de code suivant montre comment obtenir le nom du module et l'ID d'instance pour une requête :
L'ID d'instance d'un module avec scaling automatique est renvoyé sous forme de valeur unique encodée en base64, par exemple e4b565394caa
.
Vous pouvez communiquer avec les modules d'une même application en récupérant le nom d'hôte du module cible :
Vous pouvez également utiliser le service de récupération d'URL.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThe Modules API provides information about the current operating environment, including module, version, and instance details.\u003c/p\u003e\n"],["\u003cp\u003eThis API allows applications to retrieve the address of a module, version, or instance, facilitating inter-instance communication within the development and production environments.\u003c/p\u003e\n"],["\u003cp\u003eTo use the Modules API, you must include the \u003ccode\u003euse google\\appengine\\api\\modules\\ModulesService;\u003c/code\u003e statement at the top of your file.\u003c/p\u003e\n"],["\u003cp\u003eThe API can get the current module name and instance ID, and an automatically scaled module's instance ID will be a unique base64 encoded value.\u003c/p\u003e\n"],["\u003cp\u003eCommunication between modules within the same application can be achieved by fetching the hostname of the target module using the \u003ccode\u003eModulesService::getHostname()\u003c/code\u003e function.\u003c/p\u003e\n"]]],[],null,["# Using the Modules API\n\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| php-gen2\n|\n| /services/access). If you are updating to the App Engine PHP 7/8 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/php-differences) to learn about your migration options for legacy bundled services.\n\nThe Modules API provides functions that return information about the current\noperating environment (module, version, and instance).\n\nThe Modules API also has functions that retrieve the address of a module, a\nversion, or an instance. This allows an application to send requests from one\ninstance to another, in both the development and production environments.\n\nAdd the following use statement to the top of your file: \n\n use google\\appengine\\api\\modules\\ModulesService;\n\nThe following code sample shows how to get the module name and instance id for\na request: \n\n $module = ModulesService::getCurrentModuleName();\n $instance = ModulesService::getCurrentInstanceId();\n\nThe instance ID of an automatic scaled module will be returned as a unique\nbase64 encoded value, e.g. `e4b565394caa`.\n\nYou can communicate between modules in the same app by fetching the hostname of\nthe target module: \n\n use google\\appengine\\api\\modules\\ModulesService;\n\n $url = 'http://' . ModulesService::getHostname('my-backend') . '/';\n $result = file_get_contents($url);\n\nYou can also use the [URL Fetch](/appengine/docs/legacy/standard/php/issue-requests) service."]]