protected function createHotReloader()
    {
        $reload = $this->config['auto_reload'];

        if (!$reload || !\function_exists('inotify_init')) {
            return false;
        }

        $mgr     = $this;
        $options = [
            'dirs' => $reload,
            // 'masterPid' => $this->server->master_pid
        ];

        // 创建用户自定义的工作进程worker
        return new Process(function (Process $process) use ($options, $mgr) {
            $pid = $process->pid;

            $this->workerPid = $this->server->worker_pid = $pid;
            ProcessUtil::setTitle("swoole: hot-reload ({$mgr->name})");

            // $pid = $process->pid;
            $svrPid         = $mgr->server->master_pid;
            $onlyReloadTask = isset($options['only_reload_task']) ? (bool)$options['only_reload_task'] : false;
            $dirs           = array_map('trim', explode(',', $options['dirs']));

            $this->log("The <info>hot-reload</info> worker process success started. (PID:{$pid}, SVR_PID:$svrPid, Watched:<info>{$options['dirs']}</info>)");

            $kit = new HotReloading($svrPid);
            $kit
                ->addWatches($dirs, $this->config['rootPath'])
                ->setReloadHandler(function ($pid) use ($mgr, $onlyReloadTask) {
                    $mgr->log("Begin reload workers process. (Master PID: {$pid})");
                    $mgr->server->reload($onlyReloadTask);
                    // $mgr->doReloadWorkers($pid, $onlyReloadTask);
                });

            //Interact::section('Watched Directory', $kit->getWatchedDirs());

            $kit->run();
        });
    }
protected function createHotReloader()
    {
        $reload = $this->config['auto_reload'];

        if (!$reload || !\function_exists('inotify_init')) {
            return false;
        }

        $mgr     = $this;
        $options = [
            'dirs' => $reload,
            // 'masterPid' => $this->server->master_pid
        ];

        // 创建用户自定义的工作进程worker
        return new Process(function (Process $process) use ($options, $mgr) {
            $pid = $process->pid;

            $this->workerPid = $this->server->worker_pid = $pid;
            ProcessUtil::setTitle("swoole: hot-reload ({$mgr->name})");

            // $pid = $process->pid;
            $svrPid         = $mgr->server->master_pid;
            $onlyReloadTask = isset($options['only_reload_task']) ? (bool)$options['only_reload_task'] : false;
            $dirs           = array_map('trim', explode(',', $options['dirs']));

            $this->log("The <info>hot-reload</info> worker process success started. (PID:{$pid}, SVR_PID:$svrPid, Watched:<info>{$options['dirs']}</info>)");

            $kit = new HotReloading($svrPid);
            $kit
                ->addWatches($dirs, $this->config['rootPath'])
                ->setReloadHandler(function ($pid) use ($mgr, $onlyReloadTask) {
                    $mgr->log("Begin reload workers process. (Master PID: {$pid})");
                    $mgr->server->reload($onlyReloadTask);
                    // $mgr->doReloadWorkers($pid, $onlyReloadTask);
                });

            //Interact::section('Watched Directory', $kit->getWatchedDirs());

            $kit->run();
        });
    }
protected function createHotReloader ( ) { $ reload = $ this -> config [ 'auto_reload' ] ; if ( ! $ reload || ! \ function_exists ( 'inotify_init' ) ) { return false ; } $ mgr = $ this ; $ options = [ 'dirs' => $ reload , // 'masterPid' => $this->server->master_pid ] ; // 创建用户自定义的工作进程worker return new Process ( function ( Process $ process ) use ( $ options , $ mgr ) { $ pid = $ process -> pid ; $ this -> workerPid = $ this -> server -> worker_pid = $ pid ; ProcessUtil :: setTitle ( "swoole: hot-reload ({$mgr->name})" ) ; // $pid = $process->pid; $ svrPid = $ mgr -> server -> master_pid ; $ onlyReloadTask = isset ( $ options [ 'only_reload_task' ] ) ? ( bool ) $ options [ 'only_reload_task' ] : false ; $ dirs = array_map ( 'trim' , explode ( ',' , $ options [ 'dirs' ] ) ) ; $ this -> log ( "The <info>hot-reload</info> worker process success started. (PID:{$pid}, SVR_PID:$svrPid, Watched:<info>{$options['dirs']}</info>)" ) ; $ kit = new HotReloading ( $ svrPid ) ; $ kit -> addWatches ( $ dirs , $ this -> config [ 'rootPath' ] ) -> setReloadHandler ( function ( $ pid ) use ( $ mgr , $ onlyReloadTask ) { $ mgr -> log ( "Begin reload workers process. (Master PID: {$pid})" ) ; $ mgr -> server -> reload ( $ onlyReloadTask ) ; // $mgr->doReloadWorkers($pid, $onlyReloadTask); } ) ; //Interact::section('Watched Directory', $kit->getWatchedDirs()); $ kit -> run ( ) ; } ) ; }
create code hot reload worker
@see https://wiki.swoole.com/wiki/page/390.html
@return Process|false
@throws \RuntimeException
create code hot reload worker