preface

First of all, we would like to thank all the HyperF supporters. In the two years since our launch, we have been releasing a small version every week. Up to now, we have released more than 106 versions. In the future, we will continue to iterate and maintain the HyperF as we always have.

At the same time, we’re also honored to see more and more companies choose Hyperf as a framework for their projects and provide a lot of Pull requests and Bugfixs to Hyperf. So far, there are over 200 of them. Thank you for creating ecological prosperity together, we will surely live up to expectations!

Thanks ALL

In the process of continuous iteration, we have some new ideas. We iterated on these ideas, validated them, and finally settled them into version 2.2. Today, we are proud to announce the HyperF 2.2 release!

Major function iteration

DI implementation of the underlying refactoring

In version 2.2-2.1, the BetterReflection component was used to implement AOP on objects that were not managed by DI (e.g., objects instantiated by new keyword). While this brings a new programming experience, there are still some problems that have not been solved before, as follows:

  • The project starts slowly when there is no scan cache
  • Inject and Value do not work in special scenarios
  • BetterReflectionPHP 8 is not yet supported (as of release)

In the new version, we abandoned the application of BetterReflection and used the scan method of child process to solve the previous problem. All the pain points above have been solved

Describe the change in functionality in a positive light:

  • Without caching, startup time is reduced by an order of magnitude, from 5 minutes to 10 seconds for one of my company’s mega-projects!
  • Enrich theInjectAnnotation injection is applicable to scenarios, but unfortunately there is still one case where it is not valid (superclassprivateAttributes fail when injected, as in previous versions), we will continue to work on the implementation of this scenario
  • supportPHP 8AttributesNative annotation feature

In short, the DI component, as one of the core components of HyperF, has now reached a whole new level of innovation and utility

Support PHP 8

Hyperf 2.2 components are already PHP 8 compliant, and the annotations are compatible with PHP 8’s Attributes native annotations feature.

<?php
namespace App\Controller;

#[Controller]
class IndexController
{
    #[GetMapping("/test")]
    public function index()
    {
        ...
    }
}

Note that using Annotations and Attributes for the same field will ignore the Annotations (even if the Annotations are different)

<? php namespace App\Controller; /** * @Controller */ Annotations are not available */ #[Middleware(TestMiddleware::class)] class IndexController {// Use it for a single use, #[Inject] protected stdOutLoggerInterface $logger; Public function index() {public function index() {public function index() {public function index() { }}

It is important to note that while the framework already supports PHP8, it still needs to verify that the business code and dependent third-party components satisfy the PHP8 incompatibility changes when upgrading.

Reproducible comment

In previous versions, the same Annotation in the same region could not be used repeatedly:

/** * @AutoController() * @Middleware(FoomMiddleware ::class) * @Middleware(BarMiddleware::class) * Rerepeat @Middleware only one works!  */ class IndexController { }

Previously, reusing the same annotation could only be done by annotation nesting:

/** * @AutoController() * @Middlewares({ * @Middleware(FooMiddleware::class) * @Middleware(BarMiddleware::class) * }) * */ Class IndexController {}

In 2.2, we implemented repeatable annotations:

<? php namespace App\Controller; #[AutoController] #[Middleware(FooMiddleware::class)] #[Middleware(BarMiddleware::class)] class IndexController { }

When a user custom annotations need to repeat, will change the Annotation of the parent class Hyperf \ \ Di \ an Annotation AbstractMultipleAnnotation, Middleware annotate the implementation of the specific reference framework.

The configuration center was completely refactored

In previous versions, the implementation of the configuration center is implemented by the individual components, the implementation of each component varies, there are some details to achieve the difference, the code compatibility between the components is very high, in 2.2, we completely reconfigured the related components, adding the hyperf/config-center component, This component will serve as the unified access layer and abstraction layer of the configuration center, and realize the capability driving of related storage engines by combining with Driver components of other configuration centers. If hyperf/config-center + hyperf/config-apollo components are combined to realize the use of Apollo configuration center, other drivers only need to replace the corresponding driver. This transformation allows us to greatly reduce the amount of driver code, now a few lines of code and a few classes can complete a new driver access.

In the new version, the config/autoload/config_center. PHP configuration file will control all relevant information. This file can be first created by running the PHP bin/hyperf.php vendor:publish hyperf/config-center command.

Service governance component refactoring

In the previous version, the Hyperf/Service-Governance component faced the same issues as the Configuration Center. We made similar changes to the Configuration Center in this version. For example, the Hyperf/Service-Governance + Hyperf/Service-Governance-Nacos component is used to realize the use of Nacos as a service center.

When you upgrade to use, pay attention to the relative change in the configuration file, the new version will be made by the config/autoload/services. The PHP configuration file to control all the relevant information, the internal structure has certain change, This file can be created for the first time by running the PHP bin/hyperf.php vendor:publish hyperf/service-governance command.

The NaCos component was completely refactored

IMPORTANT: Be sure to reread the component documentation!!

We completely refactored the Nacos component to make its code implementation, structural layering, and API more logical, and to split the configuration center logic, service center logic, and client code that had previously been integrated into one component, as shown in the two major iteration feature introductions above.

For specific use of Nacos components, be sure to review the new documentation and follow the new documentation instructions.

AMQP component connection mechanism refactoring

We found the user use it components, very much, but as a message queue components, its performance speed of system and the effect of peak clipping news delivery/consumption speed influence is very big, we through coroutines channels (Channel) implements a multiplexing mechanism, the component’s message delivery performance increase nearly doubled! Along with the performance improvement, the stability of the connection between the client and the server is also improved.

When this component is upgraded, it switches directly to the new connection mechanism without any adjustments.

The following are the key information in the extraction of pressure test comparison:

Non-Confirm Delivery

Version 2.1

The maximum number of connections in the pool is set to 10

$ab-c 32-n 10000 http://127.0.0.1:9501/ Requests per second: 5340.80 [#/ SEC] (mean) Time per request: $ab-c 32-n 10000 http://127.0.0.1:9501/ 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 two multiplexed connections

$ab-c 32-n 10000-k http://127.0.0.1:9501/ Requests per second: 9101.44 [#/ SEC] (Mean) Time per request: $ab-c 32-n 10000-k http://127.0.0.1:9501/ 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 of connections in the pool is set to 10

$ab-c 32-n 5000-k http://127.0.0.1:9501/ Requests per second: 297.73 [#/ SEC] (mean) Time per request: $ab-c 32-n 5000-k http://127.0.0.1:9501/ Requests per second: 297.73 [#/ SEC] (mean) Time per request: 405 [ms] (Mean) Time Per Request: 1452 [ms] (Mean, Across All Concurrent Requests) Transfer Rate: 405 [ms] (Mean, Across All Concurrent Requests) Transfer Rate: 142.56 Kbytes/SEC received

Version 2.2

Set up two multiplexed connections

$ab - c - n 5000-32 k http://127.0.0.1:9501/Requests per second: 1595.94 # / SEC (mean) Time per request: [ms] (Mean)Time Per Request: 0.627 [ms] (Mean, Across All Concurrent Requests)Transfer Rate: 285.21 Kbytes/SEC received

Three Incubator components graduated into the main database

Since the Incubator mechanism was used to incubate the components, a large number of new components have been generated. It is a great pleasure to have 3 incubators graduated into the main database in version 2.2, which also means that these components have entered the stage of production availability ~

Below is a brief description of each graduated component

hyperf/dag

This component is a lightweight Directed Acyclic Graph task choreography library that makes it easy to choreograph and run tasks.

hyperf/rpc-multiplex

This component is a multiplexed RPC protocol connection component, through the use of the library can get higher performance and more stable connection RPC function;

hyperf/rpn

This component is an implementation of RPN, a form of mathematical expression introduced by the Polish mathematician Jan Vukasewicz in 1920. In RPN, all operators are placed after the operands, so it is also known as postfix notation. Inverted polish notation does not require parentheses to identify the precedence of an operator. This component completes the parsing of an inverse Polish expression.

Depend on the upgrade

  • upgradefriendsofphp/php-cs-fixerfor^ 3.0;
  • upgradepsr/containerfor1.0 | ^ ^ 2.0;
  • upgradeegulias/email-validatorfor^ 3.0;
  • upgrademarkrogoyski/math-phpfor^ 2.0;
  • upgradeleague/flysystemfor1.0 | ^ ^ 2.0;
The dependency has changed
  • # 3577 domnikl/statsdAbandoned, no longer maintained. The authors suggest usingslickdeals/statsdThe package;

The API will be deprecated soon

  • # 3636 Hyperf\Utils\ResourceWill be inv2.3Was deprecated in, please use it insteadHyperf\Utils\ResourceGenerator;

The change of subsidiary

  • # 3334 将LengthAwarePaginator::toArray()The return value of is changed to andPaginator::toArray()Is the same;
  • # 3550 从kafkaDelete thebrokerandbootstrap_server.Please use thebrokersandbootstrap_serversInstead of;
  • #3580 Change the default priority of facets to 0;
  • # 3582 将 AMQPChange the consumer label of to an empty string;
  • #3634 Use Fork Process policy instead of betterReflection policy;

    • # 3649 在hyperf/databaseusegen:modelWhen removedroave/better-reflection;
    • # 3651 在 LazyLoaderremovedroave/better-reflection;
    • # 3654Removed in other componentsroave/better-reflection;
  • # 3676usepromphp/prometheus_client_phpInstead ofendclothing/prometheus_client_php;
  • #3694 Change Hyperf\ Circuitbreaker \CircuitBreakerInterface to PHP8 support;

    • changeCircuitBreaker::inc*Counter()toCircuitBreaker::incr*Counter();
    • To change theAbstractHandler::switch()Type hints for methods;
  • # 3706 在PHP8Lt.@Middlewares({@Middleware(FooMiddleware::class)})Change the writing style of the#[Middlewares(FooMiddleware::class)];
  • # 3715refactoringnacosComponents,A certainReread the document;
  • # 3722Delete theconfig_apollo.phpThe configuration,Please switch toconfig_center.php;
  • # 3725Delete theconfig_etcd.phpThe configuration,Please switch toconfig_center.php;
  • # 3730 从kafkaremovedbrokersandupdate_brokersConfiguration;
  • # 3733Delete thezookeeper.phpThe configuration,Please switch toconfig_center.php;
  • # 3734 # 3772Split thenacosforconfig-nacosandservice-governance-nacos;
  • # 3734renamenacos-sdkThe component is callednacos;
  • #3737 Refactor configuration center and configuration driver

    • addAbstractDriverAnd combine the duplicated code into abstract classes
    • addPipeMessageInterfaceTo configure the message structure of the fetch process uniformly
  • #3817 #3818 Disconnect the service-governance-consul component from the service-governance component;
More and more
  • Other changes

Upgrade guide

We provide a detailed upgrade guide, please refer to the official documentation – 2.2 upgrade guide

Official Website and Communication

GitHub 👈👈👈👈👈 point Star support our Gitee code cloud point Star support our HyperF official website HyperF document HyperF communication group: 862099724 (Full) HyperF AC 2 Group: 811414891 (Full) HyperF AC 3 Group: 589051831 PIN 1 Group: 34538367 (Full) PIN 2 Group: 34488757