我想在codeigniter库中使用apache thrift。
我有以下代码。我已经检查了这些文件,它们是存在的。
PHP 5.6.31
0.10.*
use Thrift\Transport\TSocket;
use Thrift\Transport\TBufferedTransport;
use Thrift\Transport\THttpClient;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Exception\TException;
use Thrift\ClassLoader\ThriftClassLoader;
use \test\MyServiceClient;
class Cds2thriftclass extends Rootclass {
private $_thrift_uri = "";
private $_thrift_port = "";
private $_timeout = 5000;
private $transport;
private $protocol;
private $client;
public function __construct() {
parent::__construct();
$this->_thrift_uri = 127.0.0.1;
$this->_thrift_port = 8899;
$THRIFT_ROOT = APPPATH . 'libraries/thrift10';
require_once $THRIFT_ROOT.'/Thrift/ClassLoader/ThriftClassLoader.php';
$GEN_DIR = $THRIFT_ROOT . '/Thrift/packages';
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', $THRIFT_ROOT);
$loader->registerDefinition('test', $GEN_DIR);
$loader->register();
$this->transport = new TSocket($this->_thrift_uri, $this->_thrift_port);
$this->transport->setRecvTimeout($this->_timeout);
$this->transport = new TBufferedTransport($this->transport, 1024, 512);
$this->protocol = new TBinaryProtocol($this->transport);
$this->client = new \test\MyServiceClient($this->protocol);
Class 'test\MyServiceClient' not found in /apps/blog/application/libraries/mythriftclass.php
我在谷歌和ST中搜索这个问题,就是这个
link
这是关于,但它不能解决我的问题。
请让我知道我做错了什么。
现在问题解决了,只需使用php即可
require
func加载文件。
但无论如何,谢谢龙的帮助。
代码为blow:
$THRIFT_ROOT = APPPATH . 'libraries/thrift10';
require_once $THRIFT_ROOT.'/Thrift/ClassLoader/ThriftClassLoader.php';
$GEN_DIR = $THRIFT_ROOT . '/Thrift/packages';
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', $THRIFT_ROOT);
$loader->registerDefinition('test', $GEN_DIR);
$loader->register();
$this->transport = new TSocket('127.0.0.1', 8899);
$this->transport->setRecvTimeout($this->_timeout);
$this->transport = new TBufferedTransport($this->transport, 1024, 512);
$this->protocol = new TBinaryProtocol($this->transport);
require_once $THRIFT_ROOT . '/Thrift/gen-php/test/Types.php';
require_once $THRIFT_ROOT . '/Thrift/gen-php/test/Cds2APIService.php';
$this->client = new MyServiceClient($this->protocol);