您的位置:首页 > 业界新闻

某互联网(特大型)公司游戏元数据管理系统前端开发技术

2014-05-09 10:42 1091 查看
本人于去年十月份开始接收游戏元数据管理系统的开发,下面就把使用的技术总结一下:

由于元数据数据库比较多,链接频繁会影响效率,所以我们使用了facebook开源的Thrift,服务端使用C++,客户端链接使用python和php,由于我主要做php,下面是Thrift的php客户端入口文件:

<?php
#Thrift Lib Path Root
$GLOBALS['THRIFT_ROOT']=$_SERVER['DOCUMENT_ROOT']."/application/Thrift/lib";

#Class Namespace Turn Loader
require_once( $GLOBALS['THRIFT_ROOT'] . '/Thrift/ClassLoader/ThriftClassLoader.php' );

use Thrift\ClassLoader\ThriftClassLoader;
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift',  $GLOBALS['THRIFT_ROOT']);
$loader->register();

#All Include
require_once( $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TSocket.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TFramedTransport.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Thrift/Protocol/TBinaryProtocol.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Thrift/Exception/TException.php' );
error_reporting(E_ALL);

use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TFramedTransport;
use Thrift\Exception\TException;
use tdw_res\interity_19;
#Our Self Include
require_once( 'lib/Thrift/tdw_res/TdwInterityService.php' );
require_once( 'lib/Thrift/tdw_res/Types.php' );
class Thrift{
private $host;
private $prot;

private $socket;
private $transport;
private $protocol;
private $client;
//method
public function __construct($host='10.**.**.**',$port=9099){
$this->host=$host;
$this->port=$port;
$this->client=$this->connect($this->host,$this->port);
}
//建立连接
public function connect($host, $port){
$this->socket = new TSocket($host, $port);
$this->transport = new TFramedTransport($this->socket);
$this->protocol = new TBinaryProtocol($this->transport);
$this->client = new tdw_res\interity_19\TdwInterityServiceClient($this->protocol);
$this->transport->open();
return $this->client;
}
//关闭连接
public function close(){
$this->transport->close();
}
//操作一
public function exec_query($db_node,$sql){
try{
$db_node=$db_node;
$sql=$sql;
$result=$this->client->exec_query($db_node,$sql);
$this->close();
return $result;
}catch(TException $io){
return 'error:'.$io;
}
}
//添加、更新、删除操作
public function exec_update($db_node,$sql){
try{
$db_node=$db_node;
$sql=$sql;
$result=$this->client->exec_query($db_node,$sql);
$this->close();
return $result;
}catch(TException $io){
return 'error:'.$io;
}
}
//测试
public function test(){
return "test";
}
}

?>
上面是在程序中需要包含的文件,使用了服务端自动生成的php客户端类库文件,使用了大量的命名空间,由于我对这理解的不够深刻,暂时先写到这里,我有空会继续补充的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: