PHP 5 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 PHP 5 應用程式,即使貴機構先前曾使用機構政策重新啟用舊版執行階段的部署作業,也無法部署。現有的 PHP 5 應用程式在
淘汰日期後仍會繼續執行並接收流量。建議您
改用系統支援的最新 PHP 版本。
從單體式應用程式遷移至微服務
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
若開始使用舊版的單體式應用程式,您必須找出能夠分解並移至獨立微服務的組件。通常,結構良好的單體式應用程式會有非常自然的分區,而服務類別會做為資料儲存和業務邏輯層的介面。這類類別是將用戶端呼叫連結至微服務的理想位置。
區隔單體式應用程式中的功能
您可以採取幾種方法來區隔應用程式:
- 在應用程式中尋找可以區隔的業務邏輯。
- 找出本質上獨立的程式碼,例如使用靜態程式碼分析工具來辨別區段。
- 檢查應用程式的邏輯,找出應用程式中您可能會因不同的資源配置設定或記憶體需求而受益的部分。這樣做有機會能夠節省成本並提高資源利用率。
您可能需要重構程式碼,以移除不合常理的依附元件。我們建議在您將應用程式區隔成不同服務之前,先在舊版程式碼中執行重構作業,接著再部署到實際工作環境。
微服務的共用區域包含下列項目:
- 使用者或帳戶資訊
- 授權和工作階段管理
- 偏好設定或配置設定
- 通知和通訊服務
- 相片和媒體 (特別是中繼資料)
- 工作佇列工作站
遷移應用程式的步驟
將一組類別識別為微服務的候選類別後,接下來的步驟包括:
- 不移動現有的程式碼,並保持程式碼在舊版應用程式中運作,以加快復原作業。
- 建立新的程式碼存放區,或至少在現有存放區中建立子目錄。
- 將類別複製到新位置。
- 編寫可提供 HTTP API 掛鉤的檢視層,並以適合的方式設定回應文件的格式。
- 將新程式碼的格式設為獨立的應用程式 (建立
app.yaml
)。
- 將新的微服務部署為服務或個別專案。
- 測試程式碼,確保運作正常。
- 將資料從舊版應用程式遷移至新的微服務。請參閱下方的說明。
- 更改現有的舊版應用程式,以使用新的微服務應用程式。
- 部署更改過的舊版應用程式。
- 確認所有項目皆依照預期運作,而且不需要復原到舊版應用程式。
- 移除舊版應用程式所有無用的程式碼。
遷移運作中應用程式的資料
遷移運作中應用程式的資料可能很棘手,完全視您的狀況而定。為了便於執行更新和復原,您通常需要編寫能夠填入新舊 Cloud Datastore 實體的程式碼,方法可能是透過微服務上的臨時 API,然後編寫能夠遷移現有資料集的程式碼,例如將資料做為 MapReduce。這個過程通常會用到一些暫時性程式碼和備援資料。視您的具體狀況而定,您可能也需要在發布後執行資料遷移以跟上最新情況。提醒您,請勿以舊資料覆寫新資料。
雖然整個過程中要進行的作業似乎不少,但這些工作不會太特別。此外,在發生新微服務轉換失敗的情況下,能夠執行更新及復原作業的能力也相當重要。只有在您確認一切均已正確遷移並依預期運作後,才可以移除暫時性程式碼,並從舊的儲存位置中刪除資料。請務必在過程中隨時備份。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 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\u003eWhen transitioning from a monolithic application to microservices, identify and separate logical business units, naturally isolated code, or parts that require different scaling configurations.\u003c/p\u003e\n"],["\u003cp\u003eRefactor legacy code within the monolithic application and deploy those changes before extracting it into microservices to ensure a smoother transition.\u003c/p\u003e\n"],["\u003cp\u003eCommon microservice candidates include user data, authorization, preferences, notifications, media, and task queues, as these often represent independent functionalities.\u003c/p\u003e\n"],["\u003cp\u003eThe microservice migration process involves leaving existing code operational, creating a new code repository, developing an HTTP API layer, and subsequently testing and deploying the microservice.\u003c/p\u003e\n"],["\u003cp\u003eMigrating data in a live environment requires populating both old and new data storage simultaneously, often with temporary code and data redundancy, to enable both roll-forward and rollback capabilities.\u003c/p\u003e\n"]]],[],null,["# Migrating to Microservices from a Monolithic App\n\nWhen starting with a legacy, monolithic application, you must find parts that\ncan be carved off and moved to separate microservices. Often, a well-structured\nmonolithic app will have very natural divisions, and a service class will\nalready function as an interface to a layer of data storage and business logic.\nSuch classes are the ideal place to connect the client calls to the\nmicroservice.\n\nSeparating functionality in a monolithic app\n--------------------------------------------\n\nYou could take a couple approaches for how you separate your app:\n\n- Look for business logic in your application that can be separated.\n- Find code that is naturally isolated, such as by using static code analysis tools to identify the sections.\n- Examine your application for logic that you might benefit from different scaling configuration settings or memory requirements than the rest of your application. This could possibly result in cost savings that might lead to better resource utilization.\n\nYou might need to refactor your code to remove unnatural dependencies. We\nrecommend that you perform refactoring within your legacy code and deploy it to\nproduction before attempting to separate the app into separate services.\n\nCommon areas for microservices include the following:\n\n- User or account information\n- Authorization and session management\n- Preferences or configuration settings\n- Notifications and communications services\n- Photos and media, especially metadata\n- Task queue workers\n\nSteps for Migrating an App\n--------------------------\n\nAfter a set of classes has been identified as a candidate to become a\nmicroservice, the next steps include:\n\n- Leaving the existing code in place and operational in the legacy application to facilitate rollback.\n- Creating a new code repository, or at least a sub-directory in your existing repository.\n- Copying the classes into the new location.\n- Writing a view layer that provides the HTTP API hooks and formats the response documents in the correct manner.\n- Formulating the new code as a separate application (create an `app.yaml`).\n- Deploying your new microservice as a service or separate project.\n- Testing the code to ensure that it is functioning correctly.\n- Migrating the data from the legacy app to the new microservice. See below for a discussion.\n- Altering your existing legacy application to use the new microservices application.\n- Deploying the altered legacy application\n- Verifying that everything works as expected and that you don't need to roll back to the legacy application.\n- Removing any dead code from the legacy application.\n\nMigrating data on a live application\n------------------------------------\n\nData migration on a live application can be tricky and highly dependent on your\nsituation. Often, to facilitate roll-forward and rollback, you will need to\nwrite code that populates both the old and new Cloud Datastore entities,\npossibly by using a temporary API on the microservice, and then write code that\nmigrates\nthe existing set of data, for example as a MapReduce. This process will usually\ninvolve some amount of temporary code and redundant data. Depending on the\nspecifics of your situation, you may also need to execute a catch-up data\nmigration after you release. Be careful not to overwrite newer data with older\ndata.\n\nWhile this seems like a lot of work, it's a common occurrence and is important\nto allow for rolling forward and rolling back in the event that the cutover to\nthe new microservice does not succeed. You can remove your temporary code and\ndelete the data from the old storage location only after you have verified that\neverything is migrated correctly and everything is operating as expected. Be\nsure to make backups along the way.\n\nWhat's next\n-----------\n\n- Get an overview of [microservice architecture on App Engine](/appengine/docs/legacy/standard/php/microservices-on-app-engine).\n- Understand how to [create and name dev, test, qa, staging, and production environments with microservices in App Engine](/appengine/docs/legacy/standard/php/creating-separate-dev-environments).\n- Learn the [best practices for designing APIs to communicate between microservices](/appengine/docs/legacy/standard/php/designing-microservice-api).\n- Learn the [best practices for microservice performance](/appengine/docs/legacy/standard/php/microservice-performance)."]]