Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
O tempo de execução do PHP
A função do Cloud Run é executada em um ambiente que consiste em uma versão do sistema
operacional, além de pacotes complementares, suporte a linguagens e a biblioteca
do Functions Framework que dá suporte e invoca a função.
Esse ambiente é identificado pela versão da linguagem e conhecido como ambiente de execução.
Esses ambientes de execução usam nginx e PHP-FPM para exibir solicitações. Para saber mais sobre ambientes de execução em geral e qual versão do Ubuntu cada ambiente de execução PHP usa, consulte o Ambiente de execução das funções do Cloud Run.
Selecionar o ambiente de execução
As funções do Cloud Run dão suporte a várias versões do PHP, que estão listadas na
página Suporte ao ambiente de execução. Selecione
seu ambiente de execução PHP preferencial para a função durante a implantação.
gcloud
Se você estiver usando a Google Cloud CLI, especifique o ambiente de execução usando o parâmetro --runtime. NAME especifica o
nome da função. Por exemplo:
É possível preparar uma função diretamente do console do Google Cloud ou gravá-la na máquina local e fazer upload dela. Para preparar sua máquina local para o desenvolvimento em PHP, consulte Como usar o PHP no Google Cloud.
Para que as funções do Cloud Run encontrem a definição da sua função, seu código-fonte precisa seguir uma estrutura específica. Consulte
Como escrever funções do Cloud Run
para mais informações.
Configuração do PHP
Configure a função PHP com um arquivo php.ini no diretório raiz da função. É possível visualizar as definições de configuração do PHP com a função phpinfo(), conforme mostrado no exemplo de código a seguir:
use Psr\Http\Message\ServerRequestInterface;
function phpInfoDemo(ServerRequestInterface $request): string
{
// phpinfo() displays its output directly in the function's
// HTTP response, so we don't need to explicitly return it
//
// Note: we recommend deleting the deployed Cloud Function once you no
// longer need it, as phpinfo() may broadcast potential security issues.
phpinfo();
return '';
}
Como especificar dependências
É possível especificar dependências para a função adicionando-as a um arquivo de
projeto chamado composer.json. Para mais informações, consulte
Como especificar dependências em PHP.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-05 UTC."],[[["\u003cp\u003eCloud Run functions use \u003ccode\u003enginx\u003c/code\u003e and \u003ccode\u003ePHP-FPM\u003c/code\u003e to serve requests and run in an environment defined by the language version, known as the runtime.\u003c/p\u003e\n"],["\u003cp\u003eYou can select the preferred PHP runtime version for your function during deployment, with several versions supported and listed on the Runtime support page.\u003c/p\u003e\n"],["\u003cp\u003eFunctions can be deployed using the Google Cloud CLI with the \u003ccode\u003e--runtime\u003c/code\u003e parameter, or through the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003ePHP functions can be prepared locally or directly in the Google Cloud console, and use the PHP Functions Framework library.\u003c/p\u003e\n"],["\u003cp\u003eDependencies for your PHP function are specified in a \u003ccode\u003ecomposer.json\u003c/code\u003e file, and configurations can be managed via a \u003ccode\u003ephp.ini\u003c/code\u003e file in the root directory.\u003c/p\u003e\n"]]],[],null,["# The PHP Runtime\n===============\n\nYour Cloud Run function runs in an environment consisting of an operating\nsystem version plus add-on packages, language support, and\nthe Functions Framework library that supports and invokes your function.\nThis environment is identified by the language version, and is known as the\nruntime.\n\nThese runtimes use `nginx` and `PHP-FPM` to serve requests. To learn more\nabout runtimes in general, and to learn which Ubuntu version each PHP runtime\nuses, see the [Cloud Run functions execution\nenvironment](/functions/1stgendocs/concepts/execution-environment#php).\n\nSelect your runtime\n-------------------\n\nCloud Run functions supports several versions of PHP, listed on the\n[Runtime support](/functions/1stgendocs/runtime-support#php) page. You can\nselect the preferred PHP runtime for your function during deployment. \n\n### gcloud\n\nIf you're using the Google Cloud CLI, specify the runtime\nby using the `--runtime` parameter. \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e specifies the\nfunction name. For example: \n\n```bash\ngcloud functions deploy NAME --no-gen2 --runtime php82 --trigger-http\n```\n\nFor more deployment parameters, see [Deploy a Cloud Run function](/functions/1stgendocs/deploy#basics).\n\n### Console\n\nIf you're using the Google Cloud console, see the [Google Cloud console\nquickstart](/functions/1stgendocs/console-quickstart-1st-gen) for\ndetailed instructions.\n\nFunction preparation\n--------------------\n\nYou can prepare a function directly from the Google Cloud console or write it on\nyour local machine and upload it. To prepare your local machine for PHP\ndevelopment, see [Using PHP on Google Cloud](/php/docs).\n\nThe library that invokes your function is the [PHP Functions\nFramework](https://github.com/GoogleCloudPlatform/functions-framework-php).\n| **Note:** The only type of [event-driven functions](/functions/1stgendocs/writing#types_of_cloud_functions) PHP supports are [CloudEvent functions](/functions/1stgendocs/writing#cloudevent_functions).\n\nSource code structure\n---------------------\n\nFor Cloud Run functions to find your function's definition, your\nsource code must follow a specific structure. See\n[Writing Cloud Run functions](/functions/1stgendocs/writing#structuring_source_code)\nfor more information.\n\nPHP Configuration\n-----------------\n\nYou configure your PHP function with a [`php.ini`\nfile](https://www.php.net/manual/en/configuration.file.php) in your function's\nroot directory. You can view existing PHP configuration settings with the\n[`phpinfo()`](https://www.php.net/manual/en/function.phpinfo.php) function as\nshown in the following code sample: \n\n \n use Psr\\Http\\Message\\ServerRequestInterface;\n\n function phpInfoDemo(ServerRequestInterface $request): string\n {\n // phpinfo() displays its output directly in the function's\n // HTTP response, so we don't need to explicitly return it\n //\n // Note: we recommend deleting the deployed Cloud Function once you no\n // longer need it, as phpinfo() may broadcast potential security issues.\n phpinfo();\n return '';\n }\n\nSpecifying dependencies\n-----------------------\n\nYou specify dependencies for your function by adding them to a project file\ncalled `composer.json`. For more information, see [Specifying dependencies in\nPHP](/functions/1stgendocs/writing/specifying-dependencies-php)."]]