PHP-2PC Hprose分布式示例
1.服務(wù)器或虛擬機(jī)
虛擬機(jī)三臺(tái)centos6.5
IP:10.211.55.100 10.211.55.101 10.211.55.106
2.ip:10.211.55.100
php5.6
mysql5.7 order數(shù)據(jù)庫
nginx配置
rpc.com
order.server.rpc.com
3.ip:10.211.55.101
mysql5.7
4.ip:10.211.55.106
php5.6
nginx配置
order.server.rpc.com
5.hosts配置
本機(jī)hosts
10.211.55.100 rpc.com
虛擬機(jī)10.211.55.100 hosts
10.211.55.100 order.server.rpc.com
10.211.55.106 goods.server.rpc.com
6.數(shù)據(jù)庫
10.211.55.100 創(chuàng)建order數(shù)據(jù)庫,增加order表
CREATE TABLE `order` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`order_no` varchar(32) DEFAULT NULL,
`goods_id` int(11) DEFAULT NULL,
`goods_name` varchar(255) DEFAULT NULL,
`goods_num` int(11) DEFAULT NULL,
`create_time` int(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
10.211.55.101 創(chuàng)建goods數(shù)據(jù)庫窒盐,增加goods表
goods數(shù)據(jù)庫
CREATE TABLE `goods` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`num` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
INSERT INTO `goods` VALUES ('1', '商品1', '1000'), ('2', '商品2', '999');
7. 測試代碼
1.未使用RPC HPRose
http://rpc.com/xa_test.php
2.RPC HPRose order goods 分布事務(wù)XA使用
http://rpc.com/xa_test_hprose.php
3.RPC HPRose goods 測試
http://rpc.com/xa_test_hprose_2.php
4.RPC HPRose order 測試
http://rpc.com/xa_test_hprose_3.php
github代碼地址: https://github.com/jingyanlei/PHP-2PC