Hyperf version 2.2 released| Enterprise level progressive PHP collaboration framework



First of all, thank all hyperf supporters. In the two years since its release, we have insisted on releasing a small version every week. Up to now, more than 106 versions have been released. This is the most direct way for hyperf team to convey its persistence and responsibility to users. We explain everything with actions, In the future, we will continue to maintain the iteration and maintenance of hyperf as usual.

At the same time, we are also honored to see that more and more companies choose hyperf as the framework of their projects, and feed back a lot of pull requests and bugfixs to hyperf. At present, hyperf has more than 200 contributors. Thank you for creating ecological prosperity together. We must live up to expectations!

Thanks ALL

Hyperf version 2.2 released| Enterprise level progressive PHP collaboration framework

In the process of continuous iteration, we have produced some new ideas. We iterated and verified these ideas, and finally precipitated them into version 2.2. Today, we are honored to announce to you that hyperf version 2.2 is released!

Main function iteration

Di underlying implementation refactoring

In version 2.0-2.1, in order to implement AOP, it acts on non Di managed objects (such asnewKeyword instantiated object), the underlying implementation adoptsBetterReflectionComponents to realize relevant functions and bring new programming experience, but there are still some problems that have not been solved before, as follows:

  • Slow project startup without scan cache
  • Under special circumstancesInject and value are not valid
  • BetterReflectionPHP 8 is not yet supported (as of release)

In the new version, we abandoned itBetterReflectionThe application ofHow child processes are scannedTo solve previous problems,We have solved all the above pain points~

Describe the change of this function in a positive perspective:

  • Without cache, the startup time is reduced by an order of magnitude. Taking a giant project of the author’s company as an example, the original startup time is up to 5 minutes, and the new version takes only 10 seconds!
  • EnrichedInjectAnnotation injection is applicable to the scenario, but unfortunately there is still one case where it is invalid (parent class)privateAttribute injection fails, which is consistent with the performance of previous versions). We will continue to strive to overcome the implementation of this scenario
  • supportPHP 8andAttributesNative annotation features

In short, as one of the core components of hyperf, di component has now reached a new stage, full of innovation and practical value~

Support PHP 8

Hyperf 2.2 components have been adaptedPHP 8, annotations are also compatiblePHP 8ofAttributesNative annotation features.

namespace App\Controller;

class IndexController
    public function index()

It should be noted that,At the same time in the same areauseAnnotationsandNative attributes, the bottom layer willIgnore annotations(even if the notes are different)

namespace App\Controller;

 * @Controller
 *Annotations are invalid when the same area is used at the same time
class IndexController
    //Used alone, it can support
    protected StdoutLoggerInterface $logger;
     *Used alone, it can support
     * @GetMapping("/test")
    public function index()

It should be noted that although the framework has been supportedPHP8However, when upgrading, you still need to confirm whether the business code and dependent third-party components meet the requirementsPHP 8 incompatible changes

Repeatable annotation

In previous versions, the same area was the sameAnnotationCannot reuse:

 * @AutoController()
 * @Middleware(FooMiddleware::class)
 * @Middleware(BarMiddleware::class)
 *Duplicate @ middleware. Only one is valid!
class IndexController

Previously, reusing the same annotation can only be achieved by annotation nesting:

 * @AutoController()
 * @Middlewares({
 *     @Middleware(FooMiddleware::class)
 *     @Middleware(BarMiddleware::class)
 * })
 *Very cumbersome, adding additional mental burden
class IndexController

In 2.2, we implementedRepeatable annotation:

namespace App\Controller;

class IndexController

When the user-defined annotation needs to be repeatable, change the parent class of the annotation toHyperf\Di\Annotation\AbstractMultipleAnnotationYou can refer to the frame for detailsMiddlewareImplementation of annotations.

Complete reconfiguration of configuration center

In previous versions, the implementation of the configuration center was implemented by various scattered components. The implementation of each component varies, with some differences in details. The code coincidence degree between components is also very high. In version 2.2, weComplete reconstructionRelated components andhyperf/config-centerComponent, which will serve as the unified access layer and abstraction layer of the configuration center, and realize the capability driving of relevant storage engines by combining the driver components of other configuration centers, such ashyperf/config-center + hyperf/config-apolloComponents are used together to realize the use of the Apollo configuration center. Other drivers only need to replace the corresponding drivers. This transformation has greatly reduced the amount of driver code. Now a few lines of code and several classes can complete the access of a new driver.

When upgrading and using, pay attention to the changes of relevant configuration files. The new version will be updated byconfig/autoload/config_center.phpThe configuration file controls all relevant information. The file can be created for the first time by runningphp bin/hyperf.php vendor:publish hyperf/config-centerCommand generation.

Service governance component refactoring

Previous versions,hyperf/service-governanceThe problems faced by components and the configuration center are also the same. In this version, we have made similar changes to the configuration center, such ashyperf/service-governance + hyperf/service-governance-nacosComponent to implement the use of Nacos as a service center.

When upgrading and using, pay attention to the changes of relevant configuration files. The new version will be updated byconfig/autoload/services.phpThe configuration file controls all relevant information. The internal structure has changed to some extent. The file can be created for the first time by runningphp bin/hyperf.php vendor:publish hyperf/service-governanceCommand generation.

Complete reconfiguration of Nacos components

Important: be sure to reread the component documentation!!!

We’ve done some research on the Nacos componentComplete refactoring, make the code implementation, structure layering and API of the component more reasonable, and split the configuration center logic, service center logic and client code originally integrated in one component, as shown in the introduction of the above two main iterative functions.

For specific use of Nacos components, you must re read the new document and use it according to the new document instructions.

AMQP component connection mechanism reconfiguration

We found that there are many users using AMQP component, and as a message queue component, its performance speed has a great impact on the peak shaving effect and message delivery / consumption speed of the systemCo process channelA multiplexing mechanism is implemented, which nearly doubles the message delivery performance of the component! While improving the performance, it also improves the connection stability between the client and the server.

After the component is upgraded, it will be directly switched to the new connection mechanism without any adjustment.

The following is the key information extracted from the pressure measurement comparison:

Non confirm mode delivery

Version 2.1

The maximum number in the connection pool is set to 10

$ ab -c 32 -n 10000
Requests per second:    5340.80 [#/sec] (mean)
Time per request:       5.992 [ms] (mean)
Time per request:       0.187 [ms] (mean, across all concurrent requests)
Transfer rate:          928.38 [Kbytes/sec] received

Version 2.2

Set up 2 multiplexed connections

$ ab -c 32 -n 10000 -k
Requests per second:    9101.44 [#/sec] (mean)
Time per request:       3.516 [ms] (mean)
Time per request:       0.110 [ms] (mean, across all concurrent requests)
Transfer rate:          1626.53 [Kbytes/sec] received

Confirm mode delivery

Version 2.1

The maximum number in the connection pool is set to 10

$ ab -c 32 -n 5000 -k 
Requests per second:    797.73 [#/sec] (mean)
Time per request:       40.114 [ms] (mean)
Time per request:       1.254 [ms] (mean, across all concurrent requests)
Transfer rate:          142.56 [Kbytes/sec] received

Version 2.2

Set up 2 multiplexed connections

$ ab -c 32 -n 5000 -k per second:    1595.94 [#/sec] (mean)Time per request:       20.051 [ms] (mean)Time per request:       0.627 [ms] (mean, across all concurrent requests)Transfer rate:          285.21 [Kbytes/sec] received

Three incubator components enter the main library after graduation

Since the incubator mechanism was adopted to incubate components, a large number of new components have been generated. It is a great honor that in version 2.2, three incubator components graduated and entered the main library, which also means that these components have entered the production and availability stage~

The following are the components of each graduation and their introduction


The component is a lightweight directed acyclic graph(Directed Acyclic GRap) task layout library, which can easily complete the layout and operation of tasks.


The component is an RPC Protocol connection component that realizes multiplexing. By using the library, RPC functions with higher performance and more stable connection can be obtained;


This component is an implementation component of inverse Polish notation,RPNIt is a mathematical expression method introduced by Polish mathematician Jan vukasevich in 1920. In inverse Polish notation, all operators are placed after operands, so it is also called suffix representation. Inverse Polish notation does not require parentheses to identify the priority of the operator. Through this component, you can complete the parsing of the inverse Polish expression.

Dependency upgrade

  • upgradefriendsofphp/php-cs-fixerby^3.0;
  • upgradepsr/containerby^1.0|^2.0;
  • upgradeegulias/email-validatorby^3.0;
  • upgrademarkrogoyski/math-phpby^2.0;
  • upgradeleague/flysystemby^1.0|^2.0;
Dependency changed
  • #3577 domnikl/statsdAbandoned and no longer maintained. The author suggests usingslickdeals/statsdPackage;

Deprecating API

  • #3636 Hyperf\Utils\ResourceWill be inv2.3Deprecated in, use insteadHyperf\Utils\ResourceGenerator

Change details

  • #3334takeLengthAwarePaginator::toArray()The return value of is changed to andPaginator::toArray()Consistency of;
  • #3550fromkafkaDeletedbrokerandbootstrap_serverPlease usebrokersandbootstrap_serversReplace;
  • #3580Change the default priority of the slice to 0;
  • #3582takeAMQPThe consumer tag of is changed to an empty string;
  • #3634useFork ProcessPolicy replacementBetterReflection Strategy;

    • #3649stayhyperf/databaseusegen:modelTime shift additionroave/better-reflection
    • #3651stayLazyLoaderRemoved fromroave/better-reflection
    • #3654Removed in other componentsroave/better-reflection
  • #3676usepromphp/prometheus_client_phpreplaceendclothing/prometheus_client_php
  • #3694changeHyperf\CircuitBreaker\CircuitBreakerInterfaceFor supportPHP8

    • changeCircuitBreaker::inc*Counter()reachCircuitBreaker::incr*Counter()
    • ChangedAbstractHandler::switch()Method type prompt;
  • #3706stayPHP8Lieutenant general@Middlewares({@Middleware(FooMiddleware::class)})Change your writing style to#[Middlewares(FooMiddleware::class)]
  • #3715restructurenacosComponents,certainTo reread the document;
  • #3722Deletedconfig_apollo.phpto configure,Please useconfig_center.php
  • #3725Deletedconfig_etcd.phpto configure,Please useconfig_center.php
  • #3730fromkafkaDeleted inbrokersandupdate_brokersto configure;
  • #3733Deletedzookeeper.phpto configure,Please useconfig_center.php
  • #3734 #3772Splitnacosbyconfig-nacosandservice-governance-nacos
  • #3734renamenacos-sdkThe component name isnacos
  • #3737Refactoring the configuration center and configuration drivers

    • add toAbstractDriverAnd merge the duplicate code into the abstract class
    • add toPipeMessageInterfaceGet the message structure of the process with unified configuration
  • #3817 #3818Separate the service governance consumer component from the service governance component;

Upgrade Guide

We provide a detailed upgrade guide. Please refer to the official documentation-2.2 upgrade Guide

Official website and communication

GithubPoint star to support us
Gitee code cloudPoint star to support us
Hyperf official website
Hyperf document
Hyperf communication group: 862099724 (full)
Hyperf AC group 2: 811414891 (full)
Hyperf communication group 3: 589051831
Nail group: 34538367 (full)
Nail group II: 34488757