About Swoft

Swoft is the most popular enterprise-level PHP application development framework based on Swoole. A large number of developers use the Svoft Framework to create high-performance, easy-to-test and reusable code.

Since the release of the Swoft open source framework on March 6, 2018, it has been iteratively upgraded, adhering to the principle of simplicity, efficiency and stability. With the 1.x development iteration and Swoole 4 full coroutine, the underlying architecture of 1.x is no longer suitable. From November 2018, planning 2.x, the underlying experience of 1.x is completely rewritten, and the Swoole Hook method framework is fully coordinated. The overall framework is simpler than 1.x, and the stability is improved by one grade.

Swoft is a lightweight framework where all components can be customized and used on demand.

The Swoft framework can be used to develop any web application, build high-performance web systems, APIs, middleware, basic services, and more.

Swoft advantage

The following is a list of the many benefits of using the Swoft Framework

  • Developed in a componentized way, developers can customize and load on demand.
  • The framework is a well-designed Web MVC framework that provides a good choice for web frameworks.
  • To make it easier for PHP developers to get started, the use of databases and caches is highly compatible with Laravel.
  • All components are strictly combined with unit testing and stress testing


Swoft is the first Swoole-based annotation framework. The annotations are heavily referenced to SpringBoot , simplified on top of it, designed to be more suitable for PHP development, and easier to use.

Dependency injection (DI)

The technology that Swoft most agrees with is the dependency injection (DI) that controls inversion. This Control Inversion (IOC) is a general concept that can be expressed in many different ways. Dependency injection is just a concrete example of control reversal.

When writing complex PHP applications, the application classes should be as independent as possible from other PHP classes to increase the likelihood of reusing them and testing them independently of other classes during unit testing. Dependency injection helps to glue these classes together while keeping them separate.

What is complete dependency injection? We look at these two words separately. The dependency part here is transformed into an association between the two classes. For example, class A depends on class B. Now let's look at the second part, injecting. All this means that Class B will be injected into Class A by IoC.

Dependency injection can be done by passing arguments to the constructor or by post-constructing using setter methods. Since dependency injection is at the heart of the Swoft framework, we will explain this concept in a separate chapter of the related example.

Connection pool (Pool)

Relying on the Swoole framework's own connection pool, it can be used with simple configuration without any other cost.


The framework encapsulates a set of high-performance RPC services. Each RPC call can be used like a local function. The service rules the rules through interfaces, completely obscuring the implementation details, greatly improving development efficiency and reducing maintenance costs.

Aspect Oriented Programming (AOP)

One of Swoft's key components is the Aspect Oriented Programming (AOP) framework. The ability to span multiple points in an application is called crosscutting concerns, which are conceptually separated from the application's business logic. There are a variety of common good examples, including logging, declarative transactions, security, caching, and more.

The key unit of modularity in OOP is the class, and in AOP, the modular unit is the facet. DI helps you separate application objects from each other, and AOP helps you separate cross-cutting concerns from the objects they affect.

The AOP module of the Swoft framework provides a face-oriented programming implementation that allows you to define method interceptors and pointcuts to cleanly separate code that implements functions that should be separated. We will discuss the concept of Swoft AOP more in a separate chapter.