1.8.0

客户端

服务器端

多端口多协议示例:

$serv = new swoole_server("0.0.0.0", 9501);

$port2 = $serv->listen('127.0.0.1', 9502, SWOOLE_SOCK_TCP);

$port2->set(array(
	'open_length_check' => true,
    'package_length_type' => 'N',
    'package_length_offset' => 0,       //第N个字节是包长度的值
    'package_body_offset' => 4,       //第几个字节开始计算长度
    'package_max_length' => 2000000,  //协议最大长度
));

$port2->on('receive',  function (swoole_server $serv, $fd, $from_id, $data)  {
    echo "ServerPort2\n";
});

$serv->on('connect', function ($serv, $fd, $from_id){
	echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Connect.\n";
});

$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
	echo "[#".$serv->worker_id."]\tClient[$fd]: $data\n";
    if ($serv->send($fd, "hello\n") == false)
    {
        echo "error\n";
    }
});

$serv->on('close', function ($serv, $fd, $from_id) {
	echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Close.\n";
});

$serv->start();

其他

swoole_table保存Key值会增加内存占用,如table的size为100万,KEY值存储会增加64M内存占用

问题修复

移除特性