/ WangYa phpFrame Application
home: www.2cms.com mail: wangya@2cms.com
Copyright WangYa
Trademark WangYa
2017 New year
/
error_reporting( E_ALL);
$BAT = 1;
if(isset( $_SERVER['HTTP_HOST'] ))exit( 'no cli');
define('ONGHEAD','');
define('ONGPHP' , dirname(__FILE__).'/../ong/');
define('ONGTEMP' , 'temp');
define(\"大众ONGCON\"大众, '');
define(\"大众ONGDB\公众, '');
define('ONGNAME' , 'swjinhua');
define('ONGQHTPL', '');
define('ONGQQTPL', '');
/分解做事端标识/
$AC = $_SERVER['argv'];
$_SERVERID = (float)isset($AC['1'])?$AC['1']:0;
/绑定做事地址/
$_POST['serverip'] = '120.26.91.185';
/绑定做事端口/
$_POST['serverpt'] = 8000 + $_SERVERID;
/运行用户身份/
$_POST['USER'] = 'root';
/做事器名称/
$_POST['GAMENM'] = 'Tie Jinhua';
$_POST['gameid'] = 'gamejinhua';
/游戏逻辑处理间隔(毫秒)/
$_POST['addtime'] = 88;
$_POST['cmw'] = 300;
$_POST['cmh'] = 300;
/用户授权数据行数 比较小/
$_POST['tableshqu'] = 999;
/缓存用户数据行数/
$_POST['tableuser'] = 9999;
/缓存游戏房间行数/
$_POST['tablegame'] = 999;
/缓存CC防御ip行数/
$_POST['tableccfy'] = 99999;
$_POST['mefen'] = array( 1 , 2, 4 , 10 ); //闷分吸收下注
$_POST['yafen'] = array( 2 , 4 , 10, 20 ); //看牌的人
$_POST['zofen'] = array( 1 , 2 , 4 , 10 , 20 ); //总的筹码标注
/开启线程/
$_POST['JCNUM'] = 20;
require ONGPHP.'ong.php';
$SQTOKEN = new swoole_table($_POST['tableshqu']);
$SQTOKEN->column('u', swoole_table::TYPE_INT, 8);
$SQTOKEN->create();
/用户缓存/
$USERCC = new swoole_table($_POST['tableuser']);
$USERCC->column('u', swoole_table::TYPE_INT, 8); /用户uid/
$USERCC->column('z', swoole_table::TYPE_INT, 8); /用户fid/
$USERCC->column('f', swoole_table::TYPE_INT, 8); /游戏房间id/
$USERCC->column('t', swoole_table::TYPE_STRING, 96);/用户token/
$USERCC->create();
/游戏做事数据库/
$GAMECC = new swoole_table($_POST['tablegame']);
$GAMECC->column('atime', swoole_table::TYPE_INT, 8); / 游戏创建韶光 /
$GAMECC->column('isfguan', swoole_table::TYPE_INT, 8); / 房管uid/
$GAMECC->column('off', swoole_table::TYPE_INT, 8); /游戏状态/
$GAMECC->column('allqishu', swoole_table::TYPE_INT, 8); /游戏总期数/
$GAMECC->column('qishu', swoole_table::TYPE_INT, 8);/游戏当前期数/
$GAMECC->column('menfen', swoole_table::TYPE_INT, 8); /用户的闷分/
$GAMECC->column('xianfen', swoole_table::TYPE_INT, 8); /用户看牌分/
$GAMECC->column('alltongji', swoole_table::TYPE_STRING, 800); /所有数据统计 序列化 /
$GAMECC->column('tongji', swoole_table::TYPE_STRING, 800); / 当前局数统计/
$GAMECC->column('fangmm', swoole_table::TYPE_STRING, 96); / 房间密码/
$GAMECC->column('userinfo', swoole_table::TYPE_STRING, 2000); /所有用户信息/
$GAMECC->column('shuohua', swoole_table::TYPE_INT, 4); /当前说话用户/
$GAMECC->column('endd', swoole_table::TYPE_INT, 4); /用户末了动作/
$GAMECC->column('cmw', swoole_table::TYPE_STRING, 10000); /筹码/
$GAMECC->column('user', swoole_table::TYPE_STRING, 300); /拜会游戏的用户/
$GAMECC->column('dongzuo', swoole_table::TYPE_STRING, 600); /所有人动作/
$GAMECC->column('pai', swoole_table::TYPE_STRING, 600);/用户牌数据/
$GAMECC->column('ctime',swoole_table::TYPE_INT, 8); /游戏状态韶光/
$GAMECC->column('yctime',swoole_table::TYPE_INT, 8); /延迟韶光/
$GAMECC->create();
/ 防御CC k j 防御的数量/
$FANGYUCC = new swoole_table($_POST['tableccfy']);
$FANGYUCC-> column('j', swoole_table::TYPE_INT, 8);
$FANGYUCC-> create();
$server = new swoole_websocket_server( $_POST['serverip'] , $_POST['serverpt'] );
履历积累 单做事器 结合swoole_table 实现 websocket 游戏做事端 框架
Table
swoole_table一个基于共享内存和锁实现的超高性能,并发数据构造。用于办理多进程/多线程数据共享和同步加锁问题
swoole_table的上风
性能刁悍,单线程每秒可读写100万次
无需加锁,swoole_table内置行锁自选锁,所有操作均是多线程/多进程安全。用户层完备不须要考虑数据同步问题。
支持多进程,swoole_table可以用于多进程之间共享数据
swoole_table利用行锁,而不是全局锁,仅当2个进程在同一CPU韶光,并发读取同一条数据才会进行发生抢锁
table set 的灵巧性
分布式设计 根据 房间id 分配到 不同的做事
踩入的坑 Redis 和 memcached 利用tcp 连接 通信 增加额外开销 一个get失落效 所有数据将错乱 慎用 (该当是业务逻辑问题 主要 唯一性数据要担保100% 可有 才行)