Design and Implementation of an Asynchronous PHP Microservice Framework Based on Swoole

This article presents the design, reconstruction, and deployment of an asynchronous, event‑driven PHP microservice framework built on Swoole, detailing its background, technical objectives, serialization, RPC architecture, coroutine handling, service governance, and performance improvements for high‑concurrency rental‑business applications.

58 Tech
58 Tech
58 Tech
Design and Implementation of an Asynchronous PHP Microservice Framework Based on Swoole

Introduction: The article describes how a PHP microservice framework was refactored to an asynchronous, event‑driven architecture using Swoole, enabling cross‑platform microservice management while preserving development and runtime efficiency for PHP developers.

Background: The existing Java‑based SCF framework could not meet the needs of PHP‑based rental‑business services. HTTP interfaces caused load‑balancer fragility, JSON overhead, complex routing, and performance limits. PHP’s request‑per‑process model made persistent service registration and heartbeat difficult, leading to the adoption of a Swoole‑based resident‑memory RPC solution.

Technical Goals: The new framework aims to support event‑driven asynchronous programming, a multi‑threaded reactor model, synchronous/asynchronous/coroutine execution, avoidance of per‑request parsing and creation, and inter‑process communication (IPC) capabilities.

Technical Challenges: Key challenges include implementing service‑layer serialization/deserialization without relying on APCu, designing a high‑performance heartbeat and reporting mechanism using manager‑forked task processes, and converting traditional synchronous PHP code to non‑blocking coroutine execution to achieve latency reduction proportional to the number of parallel calls.

System Architecture: Service processes register with the SCF management platform, maintain long‑living connections for heartbeat, and support dynamic configuration. TCP requests are handled via binary serialization (WSCF), routed to PHP classes through reflection, and processed with resource pooling. Statistics such as function access, latency, and errors are collected via IPC and reported asynchronously.

Feature Design & Practice: The implementation covers service startup, serialization and routing, coroutine‑based asynchronous handling of downstream services (SCF, MySQL, Redis, KV, etc.), parallel request execution, connection pooling, and monitoring/reporting pipelines.

Outlook & Summary: The framework has become a company‑wide development standard, deployed across multiple rental‑business lines, reducing backend resource consumption and significantly improving system throughput and stability.

Author: Chen Yitian, Technology Department of the Rental Business, focuses on PHP ecosystem construction and performance optimization, having led the SCF reconstruction, Wfmanager extension, and PHP microservice initiatives.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendRPCAsynchronouscoroutine
58 Tech
Written by

58 Tech

Official tech channel of 58, a platform for tech innovation, sharing, and communication.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.