国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

關(guān)于webman框架相關(guān)的提問(wèn)

chaz6chez

1. webman會(huì)在服務(wù)啟動(dòng)時(shí)默認(rèn)啟動(dòng)一個(gè)httpServer,具體配置在server.php中提現(xiàn);除了該服務(wù)進(jìn)程,還可以通過(guò)process.php實(shí)現(xiàn)自定義進(jìn)程;httpServer和自定義進(jìn)程是否可以都抽象為process.php?理由如下:

  • web開(kāi)發(fā)框架可能存在一個(gè)實(shí)例啟動(dòng)會(huì)需要兩個(gè)http服務(wù)各自監(jiān)聽(tīng)不同端口,或者不啟動(dòng)httpServer只啟動(dòng)如jsonRpcServer;我們可以將httpServer抽象成與process/Monitor類(lèi)似的預(yù)制服務(wù),這時(shí)候無(wú)需再自行實(shí)現(xiàn)httpServer,甚至官方可以提供通用的其他的預(yù)制服務(wù)模板,如:wsServer、jsonRpcServer等;
  • 我認(rèn)為服務(wù)使用什么基礎(chǔ)協(xié)議是顯示性的,是基于約定的而非配置;我建議定義通用的接口來(lái)約束代碼,而非配置中填寫(xiě),具體如下:

使用TcpListenerInterface約束該服務(wù)為tcp基礎(chǔ)協(xié)議

    class HttpServer implements ProcessInterface, TcpListenerInterface
    {

        /** @var App|null */
        protected $app;

        /** @inheritDoc */
        public function onWorkerStart(Worker $worker)
        {
            require_once base_path() . '/support/bootstrap.php';
            $this->app = new App($worker, Container::instance(), Log::channel('default'), app_path(), public_path());
            Http::requestClass(config('app.request_class', config('server.request_class', Request::class)));
        }

        /**
        * @param TcpConnection $connection
        * @param $data
        * @return void
        */
        public function onMessage(TcpConnection $connection, $data){
            call_user_func([$this->app, 'onMessage'], $connection, $data);
        }

        /** @inheritDoc */
        public function onWorkerStop(Worker $worker){}

        /** @inheritDoc */
        public function onWorkerReload(Worker $worker){}

        /** @inheritDoc */
        public function onWorkerExit(Worker $worker, $status, $pid){}
    }

而不是使用配置

    return [
        'listen' => 'http://0.0.0.0:8787',
        'transport' => 'tcp',
        'context' => [],
        'name' => 'webman',
        'count' => cpu_count() * 2,
        'user' => '',
        'group' => '',
        'reusePort' => false,
        'event_loop' => '',
        'stop_timeout' => 2,
        'pid_file' => runtime_path() . '/webman.pid',
        'status_file' => runtime_path() . '/webman.status',
        'stdout_file' => runtime_path() . '/logs/stdout.log',
        'log_file' => runtime_path() . '/logs/workerman.log',
        'max_package_size' => 10 * 1024 * 1024
    ];
  • helper.php源代碼中的函數(shù)worker_start()有一段關(guān)于配置services的處理,我的理解是想要實(shí)現(xiàn)類(lèi)似于微服務(wù)中的服務(wù)的關(guān)聯(lián)啟動(dòng);我個(gè)人認(rèn)為services在webman整體框架中與process自定義進(jìn)程是一個(gè)概念;比如我啟動(dòng)了一個(gè)名叫clearing-center的實(shí)例,這個(gè)實(shí)例分別會(huì)提供8787端口的restful-open-api、9797端口的restful-admin-api以及8000的JsonRpc-api,那么自定義進(jìn)程中就會(huì)有三個(gè)對(duì)應(yīng)的配置,這三個(gè)自定義進(jìn)程就應(yīng)該是clearing-center的三個(gè)子服務(wù);
    foreach ($config['services'] ?? [] as $server) {
            if (!class_exists($server['handler'])) {
                echo "process error: class {$server['handler']} not exists\r\n";
                continue;
            }
            $listen = new Worker($server['listen'] ?? null, $server['context'] ?? []);
            if (isset($server['listen'])) {
                echo "listen: {$server['listen']}\n";
            }
            $instance = Container::make($server['handler'], $server['constructor'] ?? []);
            worker_bind($listen, $instance);
            $listen->listen();
    }
  • Worker:: 靜態(tài)調(diào)用相關(guān)的屬性我的理解是和Master相關(guān),原本server.php中的相關(guān)內(nèi)容如果在將process.php和server.php進(jìn)行統(tǒng)一抽象后,我建議移至app.php;我認(rèn)為他們應(yīng)該是全局的,是所有該實(shí)例中所有進(jìn)程/服務(wù)該遵守/使用的內(nèi)容;

將start.php中master相關(guān)的內(nèi)容移至helper.php的master_init()

function master_init(array $config){
    Worker::$pidFile = $config['pid_file'] ?? runtime_path() . '/webman.pid';
    Worker::$stdoutFile = $config['stdout_file'] ?? runtime_path() . '/logs/stdout.log';
    Worker::$logFile = $config['log_file'] ?? runtime_path() . '/logs/workerman.log';
    Worker::$eventLoopClass = $config['event_loop'] ?? '';
    TcpConnection::$defaultMaxPackageSize = $config['max_package_size'] ?? 10 * 1024 * 1024;
    if (property_exists(Worker::class, 'statusFile')) {
        Worker::$statusFile = $config['status_file'] ?? '';
    }
    if (property_exists(Worker::class, 'stopTimeout')) {
        Worker::$stopTimeout = $config['stop_timeout'] ?? 2;
    }

    Worker::$onMasterReload = function () {
        if (function_exists('opcache_get_status') and function_exists('opcache_invalidate')) {
            if ($status = opcache_get_status()) {
                if (isset($status['scripts']) && $scripts = $status['scripts']) {
                    foreach (array_keys($scripts) as $file) {
                        opcache_invalidate($file, true);
                    }
                }
            }
        }
    };
}

app.php

return [
    'debug' => true,
    'error_reporting' => E_ALL,
    'default_timezone' => 'Asia/Shanghai',
    'request_class' => Request::class,
    'public_path' => base_path() . DIRECTORY_SEPARATOR . 'public',
    'runtime_path' => base_path(false) . DIRECTORY_SEPARATOR . 'runtime',
    'controller_suffix' => '',

    'event_loop' => '',
    'stop_timeout' => 2,
    'pid_file' => runtime_path() . '/webman.pid',
    'status_file' => runtime_path() . '/webman.status',
    'stdout_file' => runtime_path() . '/logs/stdout.log',
    'log_file' => runtime_path() . '/logs/workerman.log',
    'max_package_size' => 10 * 1024 * 1024
];

2. 以上內(nèi)容我都fork并實(shí)現(xiàn)在 https://github.com/chaz6chez/webman/tree/patch-1 ,但并未PR,原因是:

  • webman是否可以提供測(cè)試用例,以便我測(cè)試我的PR代碼是否合規(guī),也方便其他開(kāi)發(fā)者PR的自審;比如 https://www.dtm.pub/other/develop.html

  • webman是否可以提供issue模板或者是開(kāi)源參與的流程,用于區(qū)分是bug還是提問(wèn)亦或是Request for Comments,這樣其他開(kāi)發(fā)者可以更好的參與進(jìn)來(lái),也可以在PR的時(shí)候關(guān)聯(lián)對(duì)應(yīng)的issue;

  • webman是否可以在官網(wǎng)描述中提供并強(qiáng)調(diào)一下框架的設(shè)計(jì)哲學(xué)或者說(shuō)設(shè)計(jì)理念,以便開(kāi)源貢獻(xiàn)者或使用者能夠更深的理解框架的內(nèi)涵,統(tǒng)一思路;

1813 1 1
1個(gè)回答

walkor 打賞

1、你的想法和我一樣。目前在開(kāi)發(fā)中的1.4版本可以用process.php配置多個(gè)httpserver,也在考慮將server.php合并到process.php。但是pid_file stdout_file這部分作為服務(wù)器配置放在應(yīng)用配置app.php感覺(jué)也不太合適,單獨(dú)放在server.php又感覺(jué)啰嗦??赡苓€是要有個(gè)server.php,里面只配置pid_file stdout_file等這些,不再配置http服務(wù)。1.4版本將master內(nèi)容封裝到support/App.php 類(lèi)中了,類(lèi)似你說(shuō)的master_init()方法。

worker_start()有一段關(guān)于配置services的處理,這部分于微服務(wù)沒(méi)有關(guān)系,是用來(lái)實(shí)現(xiàn)在一個(gè)進(jìn)程內(nèi)實(shí)現(xiàn)多個(gè)端口的監(jiān)聽(tīng)。這部分用的人不多,后面可能會(huì)去掉。

2、目前沒(méi)有測(cè)試用例。沒(méi)有issue模版,issue大部分是使用咨詢,沒(méi)必要用模版。如果有小的優(yōu)化改動(dòng)直接發(fā)pr即可。

3、webman理念主頁(yè)有介紹,總結(jié)起來(lái)就是內(nèi)核盡量簡(jiǎn)單,其它靠組件、插件擴(kuò)展。

  • chaz6chez 2022-08-08

    okok,worker_start那個(gè)services的部分,我想表達(dá)的意思就是我覺(jué)得services這部分沒(méi)有太多作用,大部分功能都與自定義進(jìn)程重疊

  • liziyu 2022-08-08

    大佬們辛苦了,這是要走“微服務(wù)”路線嗎?(太菜了看不懂全憑猜)

  • chaz6chez 2022-08-08

    還是web框架啊,只是說(shuō)概念上把重復(fù)的東西抽象成一起,避免冗余的設(shè)計(jì),和微服務(wù)可能沒(méi)太大關(guān)系,只是提了一嘴

年代過(guò)于久遠(yuǎn),無(wú)法發(fā)表回答
??