swoole hot update

Hot update of the official website, I won't go into details here

https://wiki.swoole.com/wiki/page/46.html

Code directory structure

testS.php ----- 服务端
<?php
$server = new swoole_server("0.0.0.0", 9501);
$server->on('WorkerStart', function ($serv, $worker_id){
	// 热更新
	echo "WorkerStart: {$worker_id}\n";
	require_once 'test.php';
});
$server->on('connect', function ($server, $fd){
    echo "connection open: {$fd}\n";
	$test = new Test();
	$test->getTime();
});
$server->on('receive', function ($server, $fd, $reactor_id, $data) {
    $server->send($fd, "Swoole: {$data}");
    $test = new Test();
    echo "send fd: {$fd}\n";
    echo $data . "\n";
	$test->getTime();
});
$server->on('close', function ($server, $fd) {
    echo "connection close: {$fd}\n";
});
$server->start();
testC.php ----- 客户端
<?php
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
$client->on("connect", function($cli) {
    $cli->send("hello world\n");
});
$client->on("receive", function($cli, $data){
    echo "received: {$data}\n";
    $cli->send(1);
    sleep(5);
    $cli->send(2);
});
$client->on("error", function($cli){
    echo "connect failed\n";
});
$client->on("close", function($cli){
    echo "connection close\n";
});
$client->connect("0.0.0.0", 9501, 0.5);
test.php -----   操作类
<?php
class Test
{
	/**
     * [__construct 初始化]
     */
    public function __construct()
    {
        date_default_timezone_set('Asia/Shanghai'); 
    }

    public function getTime()
    {
    	echo time() . "\n";
    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324515141&siteId=291194637