How to reduce the scan time frame Hyperf

 

the reason

Hyperf Framework to prevent the user to update components, proxy cache does not lead to start the update error. Added the following hook.

{
    "scripts": {
        "post-autoload-dump": [
            "init-proxy.sh"
        ]
    }
}

The  init-proxy.sh script will execute  php bin/hyperf.php di:init-proxy the command proxy cache clean up and rebuild.

$ composer init-proxy
> init-proxy.sh
../../
Runtime cleared
Scanning app ...
Scan app completed, took 195.76692581177 milliseconds.
Scanning vendor ...
Scan vendor completed, took 510.0839138031 milliseconds.
This command does not clear the runtime cache, If you want to delete them, use `vendor/bin/init-proxy.sh` instead.
Proxy class create success.
Finish!

The above demonstration, we can clearly see the time it takes, now less than  1s in fact can also be accepted. But if your model is very large, this time may be a point of unbearable. For example, the following cases.

$ composer init-proxy
> init-proxy.sh
../../
Runtime cleared
Scanning app ...
Scan app completed, took 3063.5998249054 milliseconds.
Scanning vendor ...
Scan vendor completed, took 490.39006233215 milliseconds.
This command does not clear the runtime cache, If you want to delete them, use `vendor/bin/init-proxy.sh` instead.
Proxy class create success.
Finish!

Solution

 

The following solution is based on the correct use of Model. For example, do not use the Model annotation. Detection approach is to generate what the case does not preclude the Model directory proxy cache to see if the generation Model related agency.

So, we can take the initiative to modify the  Hyperf scan directory framework, exclude the directory model. Let us write a logic modification  annotations.php.

<?php

declare(strict_types=1);

use Symfony\Component\Finder\Finder;

return [
    'scan' => [
        'paths' => value(function () {
            $paths = [];
            $dirs = Finder::create()->in(BASE_PATH . '/app')
                ->depth('< 1')
                ->exclude(['Model']) // 此处按照实际情况进行修改
                ->directories();
            /** @var SplFileInfo $dir */
            foreach ($dirs as $dir) {
                $paths[] = $dir->getRealPath();
            }
            return $paths;
        }),
        'ignore_annotations' => [
            'mixin',
        ],
    ],
];

When we re-execute the command, you will find time to be significantly shortened.

Written in the last

 

Hyperf Swoole 4.4+ achieve high performance, high flexibility PHP coroutine frame, and a large number of built-in server coroutine common components, qualitative performance based on more traditional PHP-FPM lifting framework, while providing very high Based , also maintained an extremely flexible and scalable, standard components are based on PSR standard implementation, injection design is based on a strong dependence, to ensure that the vast majority of components or classes are replaceable and reusable.

 

Framework component library addition to the usual MySQL client coroutine version, Redis client, you can also enjoy a coroutine version of the Eloquent ORM, WebSocket server and client, JSON RPC server and client, GRPC server and client end, Zipkin / Jaeger (OpenTracing) client, Guzzle HTTP client, elasticsearch client, Consul client, ETCD client, AMQP components, Apollo distribution center, Ali cloud ACM application configuration management, ETCD distribution center, based on the token bucket flow restrictor algorithm, universal connection pool, fuses, Swagger document generation, Swoole Tracker, Blade and Smarty view engine, Snowflake global ID generator and other components, eliminating the trouble of their own to achieve the corresponding version of the coroutine.

 

Hyperf also provided into the container based on the PSR-11 dependent, annotations, the AOP Oriented Programming, based on the intermediate PSR-15, custom processes, the event manager based on the PSR-14, Redis / RabbitMQ message queue, automated model cache a very convenient feature, based on the buffer PSR-16, the Crontab second level timing task, - Search.com internationalization, the validation verification, etc., to meet the wealth of technical and business scenario scene, out of the box.

Learn more information, please visit:

Tencent T3-T4 standard boutique Daquan PHP Architect tutorial directory, as long as you read the guarantee pay rises to a higher level (continually updated)

Above hope to help everyone, many PHPer always encounter some problems and bottlenecks in the advanced time, write more business code no sense of direction, I do not know from where to start to ascend, which I compiled some information, including but not limited to: a distributed architecture, highly scalable, high-performance, high-concurrency, server performance tuning, TP6, laravel, YII2, Redis , Swoole, Swoft, Kafka, Mysql optimization, shell scripts, Docker, micro-services, Nginx, etc. more advanced knowledge required for advanced dry goods can be free for everyone to share , need to be added to my official group here .

Published 265 original articles · won praise 36 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43814458/article/details/105365128