PHP 5 已达到支持终止期限,并将于 2026 年 1 月 31 日
弃用。弃用后,您将无法部署 PHP 5 应用,即使您的组织之前曾使用组织政策重新启用旧版运行时的部署也是如此。现有的 PHP 5 应用在
弃用日期之后将继续运行并接收流量。我们建议您
迁移到最新支持的 PHP 版本。
php.ini 文件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以在 App Engine 应用中加入 php.ini 文件。该文件让您可以自定义 PHP 解析器指令的行为。
关于 php.ini
php.ini
文件应放置在应用的基本目录中(与 app.yaml
文件位于同一目录中)。在初始化 PHP 解释器之前系统会加载此文件,然后才运行应用代码。
该文件遵循与其他 .ini 文件相同的语法。下面是一个简单示例:
; This is a simple php.ini file on App Engine
;
; This is a directive set to "On"
widget_compression = "On"
php.net 上发布了一系列核心指令及其可更改的模式值。扩展程序处理的 php.ini
指令记录在扩展程序各自的页面上。
您可以替换具有以下任一可更改模式值的任意 PHP 指令:
PHP_INI_SYSTEM
PHP_INI_ALL
PHP_INI_PERDIR
请注意,App Engine 的 PHP 实现中已停用某些函数。指向这些函数的指令将不起作用。
您可以使用 extension
指令启用一组可动态加载的扩展程序。
App Engine 的 PHP 指令
以下指令仅适用于 App Engine 环境。您可以在 php.ini 文件中加入这些指令。
google_app_engine.enable_curl_lite
- 该指令设置为“1”时,启用仅适用于 App Engine 的内置 cURL 版本“cURL lite”。您可以像使用标准 cURL 函数一样使用“cURL lite”,但该版本会在后台调用网址提取(而非套接字),因此对于不具有网址提取等效方法的函数,系统将抛出 CurlLiteMethodNotSupportedException
。注意:应用无法同时启用“curl.so”扩展程序和“cURL lite”,因为后者会重载 cURL 函数。
google_app_engine.enable_functions
- 已在 App Engine 中软停用但可使用此指令重新启用的函数。函数名称将在以逗号分隔的字符串中列出:google_app_engine.enable_functions = "phpversion, phpinfo"
google_app_engine.allow_include_gs_buckets
- 允许您的应用将 include
或 require
语句与存储在 Google Cloud Storage 中的文件搭配使用。
注意:您可以将 #default#
用作默认存储桶;此值将在运行时自动替换为您当前的默认存储桶名称。
例如,您可在以英文逗号分隔的列表中列出默认存储桶和包含文件的存储桶 bucket_1
和 bucket_2
:
google_app_engine.allow_include_gs_buckets = "#default#, bucket_1, bucket_2"
您还可以指定存储桶和可以包含的文件路径,例如:
google_app_engine.allow_include_gs_buckets = "bucket_1/path_x"
系统在检查可以包含 GCS 中的哪些文件时,会将提供的路径视为前缀;文件名的开头必须与该前缀匹配,才能包含 (include) 或需要 (require) 相应文件。例如,使用以上的路径示例,提供的路径允许用户包含 gs://bucket_1/path_x/...
中的文件,因为其前缀匹配。但不包含 gs://bucket_1 or gs://bucket_1/path_y/
中的文件,因为其前缀不匹配。
如果将上传的文件移动到允许的包含分区,则系统会生成一条警告,提醒用户可能存在 LFI 攻击。如果发生这种情况,您应该考虑使用更具限制性的路径。
注意:该路径被视为文件前缀;也可以包含特定文件,例如 google_app_engine.allow_include_gs_buckets = "bucket_1/path_x.ext", "bucket_2/path_z/some_file.ext
。
google_app_engine.disable_readonly_filesystem
- 默认情况下,PHP 应用无权写入文件系统。将此指令设置为“1”可在本地开发环境中解除此限制。
但该设置不影响在生产环境中运行的应用,此类应用始终受沙盒限制的约束。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-04。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThe \u003ccode\u003ephp.ini\u003c/code\u003e file, placed in the base directory of an App Engine application, allows customization of PHP interpreter directives before application code execution.\u003c/p\u003e\n"],["\u003cp\u003eYou can override PHP directives with changeable mode values such as \u003ccode\u003ePHP_INI_SYSTEM\u003c/code\u003e, \u003ccode\u003ePHP_INI_ALL\u003c/code\u003e, and \u003ccode\u003ePHP_INI_PERDIR\u003c/code\u003e, excluding those targeting disabled functions.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine provides specific directives within \u003ccode\u003ephp.ini\u003c/code\u003e, including \u003ccode\u003egoogle_app_engine.enable_curl_lite\u003c/code\u003e to use "cURL lite," and \u003ccode\u003egoogle_app_engine.enable_functions\u003c/code\u003e to re-enable certain soft-disabled functions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egoogle_app_engine.allow_include_gs_buckets\u003c/code\u003e directive permits the use of \u003ccode\u003einclude\u003c/code\u003e or \u003ccode\u003erequire\u003c/code\u003e statements with files stored in specified Google Cloud Storage buckets, with path prefix matching.\u003c/p\u003e\n"],["\u003cp\u003eIn local development, \u003ccode\u003egoogle_app_engine.disable_readonly_filesystem\u003c/code\u003e can be set to "1" to allow filesystem writing, but this is not applicable in production due to sandbox restrictions.\u003c/p\u003e\n"]]],[],null,["You can include a php.ini file with your App Engine application. This file\nlets you customize the behavior of the PHP interpreter directives.\n\nAbout php.ini\n\nThe `php.ini` file should be\nplaced in the base directory of an application (the same directory as the\n`app.yaml` file). It is loaded when the PHP interpreter is\ninitialized, and before your application code is run.\n\nThe file follows the same syntax as\n[other .ini files](https://en.wikipedia.org/wiki/INI_file). A simple\nexample might look like: \n\n```php\n; This is a simple php.ini file on App Engine\n;\n; This is a directive set to \"On\"\nwidget_compression = \"On\"\n```\n\nA list of the core directives, along with their changeable mode values,\n[is published on php.net](http://www.php.net/manual/en/ini.list.php).\nThe `php.ini` directives handled by extensions are documented on the\nrespective pages of the extensions themselves.\n\nYou may override any PHP directive that has one of the following changeable mode values:\n\n- `PHP_INI_SYSTEM`\n- `PHP_INI_ALL`\n- `PHP_INI_PERDIR`\n\nNote that some functions\n[have been\ndisabled in the App Engine implementation of PHP](/appengine/docs/legacy/standard/php/runtime#disabled_functions). Directives that target\nthese functions will have no effect.\n\nA set of [dynamically loadable extensions](/appengine/docs/legacy/standard/php/runtime#dynamically_loadable_extensions) can be enabled using the\n`extension` directive.\n\nPHP Directives for App Engine\n\nThe following directives are specific to the App Engine environment. They can\nbe included in the php.ini file.\n\n- **`google_app_engine.enable_curl_lite`** - Enables \"cURL lite\", a built-in, App Engine-specific version of cURL, when set to \"1\". \"cURL lite\" can be used exactly as you would use the standard [cURL functions](http://php.net/manual/en/ref.curl.php), but it calls [URL Fetch](/appengine/docs/legacy/standard/php/issue-requests) under the hood rather than sockets, thus functions with no URL Fetch equivalent, throw a `CurlLiteMethodNotSupportedException`.\n\n Note: An app can't enable the \"curl.so\" extension and \"cURL lite\" at the same time,\n as the latter overloads the cURL functions.\n- **`google_app_engine.enable_functions`** - Functions that have been [soft\n disabled](/appengine/docs/legacy/standard/php/runtime#functions_that_can_be_manually_enabled) in App Engine, but can be re-enabled using this directive. List the function names in a comma delimited string: \n\n ```\n google_app_engine.enable_functions = \"phpversion, phpinfo\"\n ```\n- **`google_app_engine.allow_include_gs_buckets`** - Allows your application to use the [`include`](http://php.net/manual/en/function.include.php) or [`require`](http://us1.php.net/manual/en/function.require.php) statements with files stored in [Google Cloud\n Storage](/appengine/docs/legacy/standard/php/googlestorage).\n\n \u003cbr /\u003e\n\n Note: You can use `#default#` for the default bucket; this value\n will be automatically replaced at runtime with your current default bucket name.\n\n For example, list the default bucket, along with buckets `bucket_1` and `bucket_2`\n containing the files in a comma delimited string: \n\n ```\n google_app_engine.allow_include_gs_buckets = \"#default#, bucket_1, bucket_2\"\n ```\n\n You can also specify a bucket and path to files that can be included, for example: \n\n ```\n google_app_engine.allow_include_gs_buckets = \"bucket_1/path_x\"\n ```\n\n When the check is performed for which files may be included from Google Cloud Storage, the\n supplied path is treated as a prefix that must match the start of the file name in order for it\n to be included or required. For example using the path example above, the supplied\n path would allow users to include files from `gs://bucket_1/path_x/...`\n because the prefix matches but not from `gs://bucket_1 or gs://bucket_1/path_y/` because\n the prefix doesn't match.\n\n If an uploaded file is moved to an allowed include bucket, a warning\n is generated to alert the user to a potential\n [LFI](https://en.wikipedia.org/wiki/File_inclusion_vulnerability)\n attack. If this happens, you should consider using a more\n restrictive path.\n\n **Note:** the path is treated as a file\n prefix; so it could include a specific file\n as well, for example, `google_app_engine.allow_include_gs_buckets = \"bucket_1/path_x.ext\", \"bucket_2/path_z/some_file.ext`.\n- **`google_app_engine.disable_readonly_filesystem`** - By default PHP applications are not allowed to write to the filesystem. Setting this directive to \"1\" will lift the restriction for the local development environment. However, the setting does not apply to applications running in production, which are always subjected to the [sandbox restrictions](/appengine/docs/legacy/standard/php/runtime#the_sandbox)."]]