PHP 5 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 PHP 5 應用程式,即使貴機構先前曾使用機構政策重新啟用舊版執行階段的部署作業,也無法部署。現有的 PHP 5 應用程式在
淘汰日期後仍會繼續執行並接收流量。建議您
改用系統支援的最新 PHP 版本。
使用 Cloud Storage
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如果 PHP 5 應用程式需要在執行期間讀取及寫入檔案,或是提供如電影、圖片或其他靜態內容等檔案,建議您使用 Cloud Storage 值區。
建立應用程式時,App Engine 會建立預設值區。這個值區提供的前 5 GB 儲存空間免費,並包含 Cloud Storage I/O 作業的免費配額。您可以建立其他 Cloud Storage 值區,但只有預設值區免費提供前 5 GB 的儲存空間。
將 Cloud Storage 與 App Engine 搭配使用
如要透過 App Engine 應用程式使用 Cloud Storage 值區:
在 App Engine 專案中查看現有值區的名稱。從 Cloud Storage 上傳或下載資料時,要指定這些名稱。
建議您將 Cloud Storage 值區的名稱儲存在應用程式的環境變數中,而不是以硬式編碼的方式將這些名稱寫入應用程式的程式碼中。
在應用程式中,將 google/cloud-storage
新增至應用程式的 composer.json
檔案,並從應用程式目錄執行 composer install
,藉以宣告 Cloud Storage 為依附元件。進一步瞭解 composer。
將 Google\Cloud\Storage\StorageClient
註冊為應用程式的串流包裝函式。然後使用 gs
通訊協定讀取及寫入檔案。
請參閱註冊及使用串流包裝函式的範例。
您也可以直接使用 Google Cloud 用戶端程式庫。
使用預設值區
建立應用程式時,App Engine 會建立預設值區。這個值區提供的前 5 GB 儲存空間免費。預設值區也包含免費的 Cloud Storage I/O 作業配額。詳情請參閱定價、配額與限制一節。超過 5GB 限制的部分將須付費。
預設值區的名稱格式如下:
project-id.appspot.com
App Engine 也會在部署應用程序的新版本時,建立做為暫存空間的值區。這個值區名為 staging.project-id.appspot.com
,僅供 App Engine 使用。應用程式無法與此值區互動。
設定值區與物件權限
與應用程式相關聯的服務帳戶需要具備讀取及寫入專案中值區的權限。如要瞭解所需權限,請參閱「Cloud Storage 的 IAM 角色」。
通常,與應用程式相關聯的服務帳戶是 預設 App Engine 服務帳戶。
根據貴機構的政策設定,系統可能會自動為預設服務帳戶授予專案的編輯者角色。強烈建議您
套用 iam.automaticIamGrantsForDefaultServiceAccounts
機構政策限制,停用自動角色授予功能。如果您是在 2024 年 5 月 3 日之後建立機構,系統預設會強制執行這項限制。
如果您停用自動角色授予功能,就必須決定要將哪些角色授予預設服務帳戶,然後自行授予這些角色。
如果預設服務帳戶已具有「編輯者」角色,建議您將「編輯者」角色替換為權限較低的角色。如要安全地修改服務帳戶的角色,請使用政策模擬器查看變更的影響,然後授予及撤銷適當的角色。
如要進一步瞭解如何允許其他使用者、應用程式或專案存取值區及其內容,請參閱「設定值區權限」和「設定物件權限」的相關說明。
搭配本機開發伺服器使用 Cloud Storage
App Engine 本機開發伺服器不會模擬 Cloud Storage,因此所有 Cloud Storage 要求都必須透過網際網路傳送至實際的 Cloud Storage 值區。
定價、配額與限制
Cloud Storage 用戶端程式庫對於 Cloud Storage 的呼叫沒有相關的頻寬費用,但會產生作業費用。此外,呼叫會計入您的網址擷取配額用量,因為程式庫會使用網址擷取服務與 Cloud Storage 互動。
請注意,Cloud Storage 屬付費使用服務;系統會根據 Cloud Storage 價目表向您收費。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間: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"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThis page guides you on using the recommended Google Cloud Client Library APIs for Cloud Storage with App Engine, supporting environments beyond just App Engine.\u003c/p\u003e\n"],["\u003cp\u003ePHP 5 apps can use legacy App Engine APIs but are limited to App Engine and must upgrade to the recommended APIs for migration to newer App Engine runtimes.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine creates a default Cloud Storage bucket for each app, providing 5GB of free storage and a free quota for I/O operations, but only this default bucket offers free storage.\u003c/p\u003e\n"],["\u003cp\u003eTo use Cloud Storage, you need to list your bucket names, declare Cloud Storage as a dependency in your app using \u003ccode\u003ecomposer\u003c/code\u003e, and register \u003ccode\u003eGoogle\\Cloud\\Storage\\StorageClient\u003c/code\u003e as the stream wrapper to read and write files using the \u003ccode\u003egs\u003c/code\u003e protocol.\u003c/p\u003e\n"],["\u003cp\u003eWhile there are no bandwidth charges for Cloud Storage client library calls, operations charges apply, and these calls count against your URL fetch quota.\u003c/p\u003e\n"]]],[],null,["# Using Cloud Storage\n\n| **Key Point:** This page describes how to use the recommended APIs for Cloud Storage, which are in the [Google Cloud Client Library](https://googleapis.github.io/google-cloud-php/#/docs/cloud-storage/latest/storage/readme). These APIs enable your code to run in App Engine as well as other environments that support PHP 5.\n|\n| PHP 5 apps can continue to [use the legacy\n| App Engine APIs](/appengine/docs/legacy/standard/php/googlestorage), but such apps can only run in App Engine and will need to\n| upgrade to the recommended APIs before they can migrate to newer App Engine runtimes.\n\nIf your PHP 5 app needs to read and write files during runtime,\nor serve files such as movies, images or other static content, we recommend you\nuse a [Cloud Storage](/storage/docs) bucket.\n\nApp Engine creates a [default bucket](#default_bucket) when you create\nan app. This bucket provides the first 5GB of storage for free and includes a\nfree quota for Cloud Storage I/O operations. You can\n[create other Cloud Storage buckets](/storage/docs/creating-buckets),\nbut only the default bucket includes the first 5GB of storage for free.\n\nUsing Cloud Storage with App Engine\n-----------------------------------\n\nTo use a Cloud Storage bucket from an App Engine app:\n\n1. [View the names of the existing buckets](/storage/docs/listing-buckets)\n in your App Engine project. You'll specify these names when you\n upload or download data from Cloud Storage.\n\n We recommend that you store the names of your Cloud Storage buckets\n in your app's [environment variables](/appengine/docs/standard/reference/app-yaml#environment_variables)\n instead of hard coding them into your app.\n2. In your app, declare Cloud Storage as a dependency\n\n by adding `google/cloud-storage` to your app's `composer.json` file and running\n `composer install` from your app's directory. Learn more about\n [composer](https://getcomposer.org).\n\n \u003cbr /\u003e\n\n3.\n [Register `Google\\Cloud\\Storage\\StorageClient` as the\n stream wrapper](https://googleapis.github.io/google-cloud-php/#/docs/google-cloud/v0.122.0/storage/storageclient?method=registerStreamWrapper) for your app.\n Then use the `gs` protocol to read and write files.\n\n See an [example of registering and using the stream\n wrapper](https://github.com/googleapis/google-cloud-php/tree/master/Storage#stream-wrapper).\n\n As an alternative, you can [use the Google Cloud client library directly](/storage/docs/reference/libraries).\n\n### Using the default bucket\n\nWhen you create an app, App Engine creates a default bucket that\nprovides the first 5GB of storage for free. The default bucket also includes\na free quota for Cloud Storage I/O operations. See\n[Pricing, quotas, and limits](#pricing_quotas_and_limits) for details. You will\nbe charged for storage over the 5GB limit.\n\nThe name of the default bucket is in the following format: \n\n```\nproject-id.appspot.com\n```\n\n\u003cbr /\u003e\n\nApp Engine also creates a bucket that it uses for temporary\nstorage when it deploys new versions of your app. This bucket, named\n`staging.`\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e`.appspot.com`, is for use by\nApp Engine only. Apps can't interact with this bucket.\n\n### Setting bucket and object permissions\n\nThe service account that's associated with your app needs permissions to read\nand write to buckets in your project. To learn which permissions are required,\nsee [IAM roles for\nCloud Storage](/storage/docs/access-control/iam-roles).\n\nTypically, the\nservice account that's associated with your app is the [default\nApp Engine service\naccount](/appengine/docs/legacy/standard/php/service-account).\n\n\nDepending on your organization policy configuration, the default service account might\nautomatically be granted the [Editor role](/iam/docs/roles-overview#basic) on your\nproject. We strongly recommend that you disable the automatic role grant by [enforcing the `iam.automaticIamGrantsForDefaultServiceAccounts` organization policy\nconstraint](/resource-manager/docs/organization-policy/restricting-service-accounts#disable_service_account_default_grants). If you created your organization after May 3, 2024, this\nconstraint is enforced by default.\n\n\nIf you disable the automatic role grant, you must decide which roles to grant to the default\nservice accounts, and then [grant these\nroles](/iam/docs/granting-changing-revoking-access) yourself.\n\n\nIf the default service account already has the Editor role, we recommend that you replace the\nEditor role with less permissive roles.To safely modify the service account's roles, use [Policy Simulator](/policy-intelligence/docs/simulate-iam-policies) to see the impact of\nthe change, and then [grant and revoke the\nappropriate roles](/iam/docs/granting-changing-revoking-access).\n\n\u003cbr /\u003e\n\nFor information about allowing other users, apps, or projects to access a bucket\nand its contents, see\n[Setting bucket permissions](/storage/docs/cloud-console#_bucketpermission)\nand\n[Setting object permissions](/storage/docs/cloud-console#_permissions).\n\nUsing Cloud Storage with the local development server\n-----------------------------------------------------\n\nThe App Engine local development server doesn't emulate Cloud Storage,\nso all Cloud Storage requests must be sent over the Internet to an\nactual Cloud Storage bucket.\n\nPricing, quotas, and limits\n---------------------------\n\nThere are no bandwidth charges associated with Cloud Storage client library\ncalls to Cloud Storage. However, there are\n[operations charges](/storage/pricing#operations-pricing).\nIn addition, the calls count against your\n[URL fetch quota](/appengine/docs/quotas#UrlFetch)\nas the library uses the URL Fetch service to interact with Cloud Storage.\n\nNotice that Cloud Storage is a pay-to-use service;\nyou will be charged according to the Cloud Storage\n[price sheet](/storage/pricing)."]]