A kind of Hyperf v1.1 release, a new milestone, enterprise level PHP micro service cloud native collaboration framework

Time:2020-3-25

The past three and a half months

Since the release of hyperf 1.0 on June 20, hyperf has received a lot of attention, advice and help. Up to now, hyperf has gained a lot on GitHub1330+ stars449 + pull requests51+ Contributors3370+ commitsAt the same time, there are many open-source projects around or based on hyperf. During this period, we have released a total of 16 small versions by iterating a seamless and compatible version for hyperf every week. During this period, based on 1.0, we have addedTranslation internationalization, WebSocket, Snowflake global unique ID generator, Crontab schedule tasks in seconds, Etcd configuration center, View view (including blade and Smarty engines), Task, Swoole TrackerThere are 8 components in total. At the same time, the connection pool is added to automatically release the connection according to the frequency and automatically dynamically proxy the JSON RPC client,Hyperf\Utils\Context::override()Convenient context change method, addingxml downloadMethods.

Hyperf 1.1

With the help of community forces and our efforts day and night, hyperf is also evolving rapidly. Hyperf 1.1 was released today after the National Day holiday. This version has added many functions to hyperf and brought it closer to the ideal state. Thanks to all the distributors, this version has added validation validator component, Jaeger The call chain tracing component not only strengthens the use and function of each component, but also increases a large number of single tests, from version 1.0.16661Single survey2062Assertion conditions promoted to1120Single survey3369For more details, please refer to the update below.

Version 1.1 is not a compatible upgrade version. You need to simply adjust part of the structure of skeleton, and then upgrade all components to version 1.1. We have prepared a v1.1 upgrade guide for you to refer to. For details, please refer to the official documents.

Update content

Newly added

  • #401 NEWHyperf\HttpServer\Router\DispatchedObject is used to store the resolved routing information, which is parsed before the user middleware for subsequent use. At the same time, it fixes the problem that the middleware with parameters fails in the routing;
  • #402 added@AsyncQueueMessageAnnotation, by defining this annotation on the method, indicates that the actual running logic of this method is to deliver it to the async queue queue for consumption;
  • #418 allows sending websocket messages to any FD. Even if the current worker process does not hold the corresponding FD, the framework will automatically carry out inter process communication to realize sending;
  • #420 add a new event mechanism to the database model, and cooperate with the event scheduler of psr-15 to decouple the definition of listener to monitor model events;
  • #429 added validation form validator component, which is derived from illuminate / validation. Thank laravel development team for providing such an easy-to-use validator component;
  • #441 when the redis connection is in low usage frequency, the idle connection is automatically closed;
  • #478 is better adapted to opentracing protocol and connected to Jaeger. Jaeger is a very excellent open source end-to-end distributed call chain tracing system;
  • #500 isHyperf\HttpServer\Contract\ResponseInterfaceThe chain method call support is added to solve the problem that the original method cannot be called after the proxy method is called;
  • #523 isgen:modelCommand addedtable-mappingOptions;
  • #555 added a global functionswoole_hook_flagsTo get theSWOOLE_HOOK_FLAGSThe defined runtime hook level, you canbin/hyperf.phpadopt! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);To define the constant, i.e. runtime hook level;
  • #596 is@InjectNote addedrequiredParameters, when you define@Inject(required=false)Annotation to a member property, then it will not be thrown when the dependency does not existHyperf\Di\Exception\NotFoundExceptionException, but by defaultnullTo inject,requiredThe default value of the parameter istrue, in the case of constructor injection, you can definenullableOr set the default value tonullTo achieve the same purpose;
  • #597 increase for consumers of asyncqueue componentsConcurrentTo control the consumption rate;
  • #599 increases the function of setting the retry waiting time of the message according to the current retry times for the consumers of asyncqueue component. It can set the ladder type retry waiting for the message;
  • #619 adds handlerstackfactory class to guzzle client to create a handlerstack more easily;
  • #620 increase the mechanism of automatic restart for the consumers of asyncqueue component;
  • #629 allow to define the Apollo client in the form of a configuration fileclientIp, pullTimeout, intervalTimeoutTo configure;
  • #647 automatically append TCP response according to the configuration of servereof
  • #648 added for AMQP consumernackWhen the consumption logic returnsHyperf\Amqp\Result::NACKThe abstract consumer willbasic_nackMethod to respond to the message;
  • #654 add default callbacks and corresponding hyperf events of all swoole events;

change

  • #437 Hyperf\Testing\ClientWhen an exception is encountered, it is no longer thrown directly but handed over to the exceptionhandler process;
  • #463 simplifiedcontainer.phpFile and optimized annotation caching mechanism;

The contents of the new config / container.php file are as follows:

<?php

use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSourceFactory;
use Hyperf\Utils\ApplicationContext;

$container = new Container((new DefinitionSourceFactory(true))());

if (! $container instanceof \Psr\Container\ContainerInterface) {
    throw new RuntimeException('The dependency injection container is invalid.');
}
return ApplicationContext::setContainer($container);
  • #486 Hyperf\HttpMessage\Server\RequestOfgetParsedBodyMethod can now directly process data in JSON format;
  • #523 adjustmentgen:modelThe model class name generated by the command is singular by default. If the table name is plural, the class name generated by default is singular;
  • #614 ා 617 adjust the structure of configprovider class, andconfig/dependencies.phpFile moved toconfig/autoload/dependencies.phpAnd the file structure is removeddependenciesLayer, which also means that you candependenciesConfiguration is written toconfig/config.phpWithin the document;

Changes in data structure within config provider:
Before:

'scan' => [
    'paths' => [
        __DIR__,
    ],
    'collectors' => [],
],

Now:

'annotations' => [
    'scan' => [
        'paths' => [
            __DIR__,
        ],
        'collectors' => [],
    ],
],

Add a layer of annotations, which will be consistent with the configuration file structure and no longer special

  • #630 changedHyperf\HttpServer\CoreMiddlewareClass, usingmake()To replace it.new
  • #631 changed the instantiation method of AMQP consumer, usingmake()To replace it.new
  • #637 adjustedHyperf\Contract\OnMessageInterfaceandHyperf\Contract\OnOpenInterfaceType constraint for the first parameter of, usingSwoole\WebSocket\ServerReplaceSwoole\Server
  • #638 renameddb:modelOrder forgen:modelCommand, and added a visitor to optimize the$connectionMember properties, if the$connectionIf the value of the property is the same as the inherited parent class, the created model class will not contain this property;

remove

  • #401 removedHyperf\JsonRpc\HttpServerFactory, Hyperf\HttpServer\ServerFactory, Hyperf\GrpcServer\ServerFactoryClass;
  • #402 removed discardedAsyncQueue::delayMethod;
  • #563 removed discardedHyperf\Server\ServerInterface::SERVER_TCPConstants, usingHyperf\Server\ServerInterface::SERVER_BASETo replace;
  • #602 removedHyperf\Utils\Coroutine\ConcurrentOftimeoutParameters;
  • #612 removed something not used in ringphp handler$urlVariables;
  • #616 ා 618 removed some useless code in guzzle;

optimization

  • #644 optimizes the annotation scanning process, separatingappandvendorTwo parts to scan annotations, greatly reducing the user’s scanning time;
  • #653 optimizes the detection logic of swoole shortname. The current detection logic is more suitable for the actual configuration scenario of swoole, not onlyswoole.use_shortname = "Off"To pass the test;

repair

  • #448 fixes the problem that TCP server may not start when HTTP server or websocket server exists;
  • #623 fixed when passing anullWhen the method parameter of the proxy class is valued, the method still gets the default value of the method;

About hyperf

Hyperf is based onSwoole 4.4+The implementation of high-performance, high flexibility PHP cooperation framework, built-in cooperation server and a large number of commonly used components, performance based on traditionalPHP-FPMWhile providing ultra-high performance, our framework also maintains extremely flexible scalability. Standard components are implemented based on PSR standards, and based on strong dependency injection design, ensuring that most components or classes areReplaceableAndReusable.

In addition to the common collaborative version ofMySQL clientRedis clientIt also provides you with a collaborative version ofEloquent ORMWebsocket server and clientJSON RPC server and clientGrpc server and clientZipkin (opentracking) clientGuzzle HTTP clientElasticsearch clientConsul clientEtcd clientAMQP componentApollo configuration centerAlicloud ACM application configuration managementEtcd configuration centerCurrent limiter based on token bucket algorithmUniversal connection poolFuseSwagger document generationSwoole TrackerBlade and Smarty view engineSnowflake global ID generatorAnd other components save the trouble of implementing the corresponding version.

Hyperf also providesDependency injection container based on psr-11annotationAOP aspect oriented programmingMiddleware based on psr-15Custom processEvent manager based on psr-14Redis / rabbitmq message queueAutomatic model cachingCache based on psr-16Crontab second level scheduled taskInternationalizationAnd other very convenient functions, to meet the rich technical and business scenarios, out of the box.

Original intention of framework

Although the framework developed based on PHP language is in an era of a hundred flowers contending, it still fails to see a perfect framework where elegant design and ultra-high performance coexist, nor a framework that really paves the way for PHP microservices. This is hyperf As well as the original intention of its team members, we will continue to invest in and make efforts to this end, and welcome you to join us in the open source construction.

Design concept

Hyperspeed + Flexibility = HyperfFrom the name, we willSuper high speedandflexibilityAs a gene of hyperf.

  • For ultra-high speed, we are based on the swoole process and make a lot of optimization in the framework design to ensure the output of ultra-high performance.
  • For flexibility, we are based on the powerful dependency injection component of hyperf, which is based on the contract of PSR standard and the contract implementation defined by hyperf, so that most of the components or classes in the framework are replaceable.

Based on the above characteristics, hyperf will have rich possibilities, such as the realization of single web services, API services, gateway services, distributed middleware, micro service architecture, game servers, Internet of things (IOT), etc.

Complete documentation

We have invested a lot of time in the construction of documents to solve various problems caused by the lack of documents. Documents also provide a large number of examples, which are also friendly to novices.
Hyperf official development document

Production available

We do a lot of unit tests for components to ensure the logic is correct. Currently, there are1120Single survey3369Four assertion conditions and high-quality documents have been maintained. Before hyperf officially opened to the outside world (June 20, 2019), it had passed the test of harsh production environment, and we officially opened the project to the outside world. Now many large Internet enterprises have deployed hyperf to their own production environment and operated stably.

Official website and communication

Github 👈👈👈👈👈 Click star to support us
Gitee code cloud 👈👈👈👈👈 Click star to support us
Hyperf official website
Hyperf document
QQ group: 862099724

Recommended Today

CentOS static network configuration

cat /etc/sysconfig/network-scripts/ifcfg-ens33 DEFROUTE=”yes”IPV4_FAILURE_FATAL=”no”IPV6INIT=”yes”IPV6_AUTOCONF=”yes”IPV6_DEFROUTE=”yes”IPV6_FAILURE_FATAL=”no”IPV6_ADDR_GEN_MODE=”stable-privacy”NAME=”ens33″UUID=”1f816d46-c663-46c1-16d3-08977259b3f0″DEVICE=”ens33″ONBOOT=”yes” IPADDR=192.168.136.164NETMASK=255.255.255.0GATEWAY=192.168.136.2DNS1=114.114.114.114DNS2=8.8.8.8 Restart the network:service network restart This paper is published by the author pm1024: Java Experimental Manual, exchange: 583284584!