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\";
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\";
}
public functiononReceive( swoole_server$serv,$fd,$from_id,$data) {
$serv->reload();//当接收到客户端消息时更新代码,下次再执行work代码时变(onWorkerStart),本次执行还是不变
$this->_e->say();
echo"Get Message From Client{$fd}:{$data}\";
}
public functiononClose($serv,$fd,$from_id) {
echo"Client{$fd} close connection\";
}
}
newServer();
client:
创新互联公司是专业的泗阳网站建设公司,泗阳接单;提供成都网站设计、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行泗阳网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
$cli=newSwoole_client(SWOOLE_SOCK_TCP);
$cli->connect('127.0.0.1',9501,1);
fwrite(STDOUT,'输入消息:');
$msg=trim(fgets(STDIN));
$cli->send($msg);
本文题目:swoolereload代码热更新example
当前路径:http://pwwzsj.com/article/pjosoh.html