PHP 5 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 PHP 5 應用程式,即使貴機構先前曾使用機構政策重新啟用舊版執行階段的部署作業,也無法部署。現有的 PHP 5 應用程式在
淘汰日期後仍會繼續執行並接收流量。建議您
改用系統支援的最新 PHP 版本。
設定暖機要求以改善效能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在將應用程式的程式碼載入到新建立的執行個體時,您可以使用暖機要求來減少要求及回覆的延遲時間。
App Engine 經常需要將應用程式的程式碼載入至新的執行個體。載入執行個體作業可能會在發生以下情況時進行:
- 重新部署應用程式的版本時。
- 因要求的負載超過目前這組運作中執行個體的容量,而建立新的執行個體時。
- 基礎架構或實體硬體進行維護及修復時。
將應用程式的程式碼載入至新的執行個體時,可能會產生載入要求。載入要求可能會讓使用者面臨的要求延遲時間增加,但可使用「暖機要求」來避免此延遲時間增加情形。暖機要求會在任何即時要求到達該執行個體前,先將您應用程式的程式碼載入至新的執行個體。
如果您的應用程式啟用了暖機要求,App Engine 會嘗試偵測應用程式何時需要新的執行個體,並發出暖機要求來初始化新的執行個體。然而,嘗試偵測的功能並非在每種情況下均能有效運作。因此,即使應用程式已啟用暖機要求,仍可能會產生載入要求。舉例來說,如果您的應用程式沒有提供流量,則向應用程式發出的第一個要求一律為載入要求,而非暖機要求。
如同其他所有向 App Engine 應用程式發出的要求,暖機要求也會計入執行個體時數。在大多數啟用暖機要求的情況下,您不會發現執行個體小時數增加,因為應用程式只會在暖機要求中初始化,而非載入要求。如果您決定執行更多工作,例如在暖機要求期間進行預先快取,則執行個體小時用量可能會增加。如果您將 min_idle_instances
設為大於 0
,這些執行個體首次啟動時可能會出現暖機要求,但在該時間過後,這些執行個體仍可供使用。
啟用暖機要求
App Engine 排程器會使用暖機要求,並依據使用者提供的設定,控制執行個體的自動調整資源配置。啟用暖機要求後,App Engine 會向 /_ah/warmup
發出 GET
要求。您可以針對這個要求實作處理常式,以執行應用程式專屬的工作,例如預先快取應用程式資料。
排程器判定需要更多執行個體時,就會啟動執行個體。由於排程器會使用暖機要求啟動執行個體,因此即使停用了暖機要求,這些要求仍可能會出現在記錄檔中。
請注意,系統不保證會呼叫暖機要求,並且在某些狀況下會改為傳送載入要求,例如:該執行個體為首先啟動的執行個體,或是流量發生遽增。然而,如果暖機要求已啟用,系統會「盡可能」嘗試將要求傳送至暖機完成的執行個體。
如要啟用暖機要求,請在 app.yaml
檔案的 inbound_services
指令下方新增 warmup
元素,例如:
inbound_services:
- warmup
註冊處理常式
您可以在專案的 app.yaml
檔案中登錄處理暖機要求的指令碼。例如:
inbound_services:
- warmup
handlers:
- url: /_ah/warmup
script: warmup.php
login: admin
這個範例會註冊處理常式,以監聽透過 warmup.php
檔案向 /_ah/warmup
要求路徑發出的暖機要求。
建立處理常式
建立處理常式,以便處理傳送至 /_ah/warmup
的要求。處理常式應執行應用程式需要的任何暖機邏輯。
下列範例以前述範例為基礎:
在 PHP 5 執行階段環境中,您必須部署前端控制器來處理所有要求轉送作業 (包括 /_ah/warmup
要求)。
舉例來說,下列手動執行的前端控制器含有處理暖機要求的程式碼:
<?php
// Handle your warmup logic for your app.
switch (@parse_url($_SERVER['REQUEST_URI'])['path']) {
case '/_ah/warmup':
echo "Warmup successful";
break;
// Other handlers
// ...
}
?>
後續步驟
您可能會希望將資料值儲存於 Memcache 等記憶體內資料儲存庫,讓您的應用程式透過較少查詢迅速存取資料。
舉例來說,假設您想要建立並儲存自有網站的當前熱門文章清單,可以在暖機空間中建立清單,再將清單儲存至 Memcache。使用者要求傳入時,App Engine 不需要執行任何資料儲存庫查詢作業,應用程式也能更快速地處理使用者要求。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-19 (世界標準時間)。
[[["容易理解","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-08-19 (世界標準時間)。"],[[["\u003cp\u003eWarmup requests help reduce latency by loading your app's code into a new instance before live requests arrive.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine initiates warmup requests when a new instance is needed, attempting to initialize it before any live traffic is directed to it, though this is not always guaranteed.\u003c/p\u003e\n"],["\u003cp\u003eEnabling warmup requests involves adding the \u003ccode\u003ewarmup\u003c/code\u003e element under the \u003ccode\u003einbound_services\u003c/code\u003e directive in your \u003ccode\u003eapp.yaml\u003c/code\u003e file, which tells App Engine to issue requests to \u003ccode\u003e/_ah/warmup\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can register a specific script, like \u003ccode\u003ewarmup.php\u003c/code\u003e, to handle the \u003ccode\u003e/_ah/warmup\u003c/code\u003e requests and perform application-specific tasks such as pre-caching data.\u003c/p\u003e\n"],["\u003cp\u003eUtilizing warmup requests can also be coupled with in-memory datastores like Memcache to store pre-calculated data, further enhancing performance by reducing the need for datastore queries.\u003c/p\u003e\n"]]],[],null,["# Configuring Warmup Requests to Improve Performance\n\nYou can use warmup requests to reduce request and response latency during the\ntime when your app's code is being loaded to a newly created instance.\n\nApp Engine frequently needs to load your app's code into a fresh\ninstance. Loading an instance can happen in the following situations:\n\n- When you redeploy a version of your app.\n- When new instances are created due to the load from requests exceeding the capacity of the current set of running instances.\n- When maintenance and repairs of the underlying infrastructure or physical hardware occur.\n\nLoading your app's code to a new instance can result in [loading\nrequests](/appengine/docs/legacy/standard/php/how-instances-are-managed#loading_requests).\nLoading requests can result in increased request latency for your users, but you\ncan avoid this latency using *warmup requests*. Warmup requests load your\napp's code into a new instance before any live requests reach that instance.\n\nIf warmup requests are enabled for your application, App Engine attempts\nto detect when your application needs a new instance and initiates a warmup\nrequest to initialize a new instance. However, these detection attempts do not\nwork in every case. As a result, you might encounter loading requests, even if\nwarmup requests are enabled in your app. For example, if your app is serving no\ntraffic, the first request to the app will always be a loading request, not a\nwarmup request.\n\nWarmup requests use instance hours like any other request to your\nApp Engine application. In most cases where warmup requests are enabled,\nyou won't notice an increase in instance hours because your application is\nsimply initializing in a warmup request instead of a loading request. Your\ninstance hour usage can increase if you decide to do more work, such as\npre-caching during a warmup request. If you set\n[`min_idle_instances`](/appengine/docs/legacy/standard/php/config/appref#min_idle_instances)\nto greater than `0`, you might encounter warmup requests when those instances\nfirst start, but they will remain available after that time.\n\nEnabling warmup requests\n------------------------\n\nWarmup requests are used by the App Engine scheduler, which controls the\nauto scaling of instances based on user-supplied configuration. With warmup\nrequests enabled, App Engine issues `GET` requests to `/_ah/warmup`. You\ncan implement handlers for this request to perform application-specific tasks,\nsuch as pre-caching application data.\n\nThe scheduler starts up instances when it determines that more instances are\nneeded. Warmup requests may appear in\n[logs](/appengine/docs/legacy/standard/php/writing-application-logs#viewing_logs)\neven if they are disabled because the scheduler uses them to start instances.\n\nNote that warmup requests are not guaranteed to be called. In some situations\nloading requests are sent instead: for example, if the instance is the first one\nbeing started up, or if there is a steep ramp-up in traffic. However, there\nwill be a \"best effort\" attempt to send requests to already warmed-up instances\nif warmup requests are enabled.\n\nTo enable warmup requests, add the `warmup` element under the\n[`inbound_services`](/appengine/docs/legacy/standard/php/config/appref#inbound_services)\ndirective in your `app.yaml` file, for example: \n\n inbound_services:\n - warmup\n\n\u003cbr /\u003e\n\nRegistering your handler\n------------------------\n\nYou can register the script that handles warmup requests in your project's\n`app.yaml` file. For example: \n\n inbound_services:\n - warmup\n\n handlers:\n - url: /_ah/warmup\n script: warmup.php\n login: admin\n\nThis example registers a handler to listen to warmup requests to the\n`/_ah/warmup` request path with the\n`warmup.php` file.\n\nCreating your handler\n---------------------\n\nCreate a handler that will process the requests that are sent to `/_ah/warmup`.\nYour handler should perform any warmup logic that is needed by your app.\n\nThe following example builds on the previous example:\n\n\nIn the PHP 5 runtime environment, you need to\ndeploy a front controller to handle all request routing,\nincluding `/_ah/warmup` requests.\n\nFor example, the following manual front controller contains code to handle\nwarmup requests: \n\n \u003c?php\n // Handle your warmup logic for your app.\n switch (@parse_url($_SERVER['REQUEST_URI'])['path']) {\n case '/_ah/warmup':\n echo \"Warmup successful\";\n break;\n // Other handlers\n // ...\n }\n ?\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\nYou might want to store values in an in-memory datastore such as\n[Memcache](/appengine/docs/legacy/standard/php/memcache), giving your app\nfast, query-less access to data.\n\nFor example, if you build and store a list of the current trending articles for\nyour site, you can build that list in the warmup and store it in Memcache. When\na user request comes in, App Engine doesn't need to perform any\ndatastore queries and the application can serve the user's request faster.\n\n\u003cbr /\u003e"]]