swoolereload代码热更新example-创新互联

server:
classServer
{
  private$_serv=null;

  private$_e=null;

  public function__construct()
  {
    $this->_serv=newswoole_server("0.0.0.0",9501);
    $this->_serv->set(array(
      'worker_num'=>8,
      'daemonize'=>false,
      'max_request'=>10000,
      'dispatch_mode'=>2,
      'debug_mode'=>1,
    ));

    $this->_serv->on('Start',array($this,'onStart'));
    $this->_serv->on('WorkerStart',array($this,'onWorkerStart'));
    $this->_serv->on('Connect',array($this,'onConnect'));
    $this->_serv->on('Receive',array($this,'onReceive'));
    $this->_serv->on('Close',array($this,'onClose'));
    $this->_serv->start();
  }

  public functiononStart($serv)
  {
    echo"start\n";
    cli_set_process_title('reload_master');
  }

  public functiononWorkerStart($serv,$worker_id)
  {

    spl_autoload_register(function($class){

      $classPath=str_replace('\\','/',$class) .'.php';
      if(file_exists($classPath)) {
        include$classPath;
      }

    });

    $this->_e=new\plugin\Event();

  }

  public functiononConnect($serv,$fd,$from_id) {
    echo"Client{$fd} connect\n";

  }
  public functiononReceive( swoole_server$serv,$fd,$from_id,$data) {
    $serv->reload();//当接收到客户端消息时更新代码,下次再执行work代码时变(onWorkerStart),本次执行还是不变
    $this->_e->say();
    echo"Get Message From Client{$fd}:{$data}\n";
  }
  public functiononClose($serv,$fd,$from_id) {
    echo"Client{$fd} close connection\n";
  }

}

newServer();

client:

创新互联基于成都重庆香港及美国等地区分布式IDC机房数据中心构建的电信大带宽,联通大带宽,移动大带宽,多线BGP大带宽租用,是为众多客户提供专业服务器托管报价,主机托管价格性价比高,为金融证券行业成都服务器托管,ai人工智能服务器托管提供bgp线路100M独享,G口带宽及机柜租用的专业成都idc公司。
$cli=newSwoole_client(SWOOLE_SOCK_TCP);

$cli->connect('127.0.0.1',9501,1);

fwrite(STDOUT,'输入消息:');
$msg=trim(fgets(STDIN));

$cli->send($msg);

swoole reload 代码热更新 example

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章标题:swoolereload代码热更新example-创新互联
分享URL:http://myzitong.com/article/dpecpj.html