public function init($host = "127.0.0.1", $port = 8090) { if (false == $this->is_init) { $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', $GLOBALS['THRIFT_ROOT']); $loader->registerDefinition('openflow\\master', APPPATH . 'thirdlib/'); $loader->register(); $socket = new TSocket($host, $port); $framedSocket = new TFramedTransport($socket); $this->transport = $framedSocket; $protocol = new TBinaryProtocol($this->transport); $this->transport->open(); $client = new MasterServiceClient($protocol); $this->is_init = true; return $client; } }
private function __construct() { $GEN_DIR = realpath(dirname(__FILE__) . '/..') . '/gen-php'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', __DIR__); $loader->registerDefinition('shared', $GEN_DIR); $loader->registerDefinition('tutorial', $GEN_DIR); $loader->register(); $kafkaUrl = getconfig('kafkaUrl'); $port = getconfig('kafkaPort'); $socket = new TSocket($kafkaUrl, $port); $transport = new TBufferedTransport($socket, 1024, 1024); $transport->open(); $protocol = new TBinaryProtocol($transport); $this->client = new \com\feiniu\kafka\thrift\service\KafkaService($protocol); $this->project = getconfig('kafkaProject'); $this->topic = getconfig('kafkaTopic'); $this->kafkakey = getconfig('kafkaKey'); $this->group = getconfig('kafkaGroup'); //$this->msg = getconfig(''); }
<?php # Change this to match your thrift root. $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/Thrift'; require_once $GLOBALS['THRIFT_ROOT'] . '/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', dirname(__FILE__)); $loader->register(); # Something is wrong with this. Is this the PHP way of doing things? # Old versions of thrift seemingly worked with just a couple includes. /* require_once( $GLOBALS['THRIFT_ROOT'].'/Thrift.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Type/TMessageType.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Type/TType.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Exception/TException.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Factory/TStringFuncFactory.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/StringFunc/TStringFunc.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/StringFunc/Core.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Transport/TSocket.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Transport/TBufferedTransport.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Protocol/TBinaryProtocol.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Packages/Hbase/Hbase.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/Packages/Hbase/Types.php' ); */ require_once $GLOBALS['THRIFT_ROOT'] . '/Packages/Hbase/Hbase.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Packages/Hbase/Types.php'; use Thrift\Transport\TSocket; use Thrift\Transport\TBufferedTransport; use Thrift\Protocol\TBinaryProtocol;
<?php /** * * web页面rpc测试客户端 * http://ip:30304 例如:http://192.168.20.23:30304 * * @author liangl * */ require_once SERVER_BASE . 'thirdparty/Thrift/Thrift/ContextSerialize.php'; require_once SERVER_BASE . 'thirdparty/Thrift/Thrift/Context.php'; require_once SERVER_BASE . 'thirdparty/Thrift/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', SERVER_BASE . 'thirdparty/Thrift'); $loader->register(); class TestThriftClientWorker extends PHPServerWorker { protected $thriftServiceArray = array(); /** * 判断包是否都到达 * @see PHPServerWorker::dealInput() */ public function dealInput($recv_str) { return HTTP::input($recv_str); } /** * 处理业务逻辑 查询log 查询统计信息 * @see PHPServerWorker::dealProcess()
echo "Type: " . $_FILES["files"]["type"][0] . "<br>"; echo "Size: " . $_FILES["files"]["size"][0] / 1024 . " kB<br>"; echo "Temp file: " . $_FILES["files"]["tmp_name"][0] . "<br>"; if (file_exists("upload/" . $filename)) { echo $filename . " already exists. " . "<br>"; } else { move_uploaded_file($_FILES["files"]["tmp_name"][0], "../upload/" . $filename); echo "Stored in: " . "upload/" . $filename . "<br>"; } require_once 'Thrift/ClassLoader/ThriftClassLoader.php'; require_once 'TrustedBridge/Types.php'; require_once 'TrustedBridge/TrustedBridge.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = realpath(dirname(__FILE__) . '/..') . '/gen-php'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', '.'); $loader->registerDefinition('TrustedBridge', '.'); $loader->register(); use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\THttpClient; use Thrift\Transport\TPhpStream; use Thrift\Transport\TBufferedTransport; use Thrift\Exception\TException; try { echo "Connecting " . $server_ip . ":" . $server_port . "<br>"; $socket = new TSocket($server_ip, $server_port); $transport = new TBufferedTransport($socket, 1024, 1024); //$transport = new TBufferedTransport(new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W));; $protocol = new TBinaryProtocol($transport); $client = new \TrustedBridge\TrustedBridgeClient($protocol);
<?php namespace tutorial\php; error_reporting(E_ALL); ini_set("display_errors", "stderr"); require_once 'vendor/autoload.php'; require_once __DIR__ . '/vendor/apache/thrift/lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = dirname(__FILE__) . '/gen-php'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', __DIR__ . '/vendor/apache/thrift/lib/php/lib'); $loader->registerDefinition('Example', $GEN_DIR); $loader->register(); use Thrift\Factory\TBinaryProtocolFactory; use Thrift\Factory\TTransportFactory; use Thrift\Protocol\TBinaryProtocol; use Thrift\Server\TServerSocket; use Thrift\Server\TSimpleServer; use Thrift\Transport\TPhpStream; use Thrift\Transport\TBufferedTransport; use Thrift\Transport\TSocket; class ExampleService implements \Example\ExampleServiceIf { /** * @return string */ public function ping() { return 'ping method called '; }
<?php namespace API; //ini_set("user_agent", "PHP/THttpClient\nAccept: application/x-thrift\nContent-Type: application/x-thrift"); error_reporting(E_ALL); require_once __DIR__ . '/lib/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = realpath(dirname(__FILE__)); $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', __DIR__ . '/lib'); $loader->registerDefinition('shared', $GEN_DIR); $loader->registerDefinition('proto', $GEN_DIR); $loader->register(); /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
* Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * @package thrift.test */ namespace test\Thrift\Protocol; use Thrift\ClassLoader\ThriftClassLoader; use Thrift\Serializer\TBinarySerializer; require_once __DIR__ . '/../../../../lib/Thrift/ClassLoader/ThriftClassLoader.php'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', __DIR__ . '/../../../../lib'); $loader->registerNamespace('Test', __DIR__ . '/../../..'); $loader->registerDefinition('ThriftTest', __DIR__ . '/../../../packages'); $loader->register(); /*** * This test suite depends on running the compiler against the * standard ThriftTest.thrift file: * * lib/php/test$ ../../../compiler/cpp/thrift --gen php -r \ * --out ./packages ../../../test/ThriftTest.thrift */ class TestBinarySerializer extends \PHPUnit_Framework_TestCase { public function setUp() { }
<?php // 引入客户端文件 require_once __DIR__ . '/../Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\TFramedTransport; $thrift_dirname = dirname(__DIR__); $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', $thrift_dirname); $loader->registerNamespace('Swoole', $thrift_dirname); $loader->registerNamespace('Services', __DIR__); $loader->registerDefinition('Services', __DIR__); $loader->register(); $socket = new TSocket('127.0.0.1', 8091); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport); $transport->open(); $client = new Services\HelloSwoole\HelloSwooleClient($protocol); $message = new Services\HelloSwoole\Message(array('send_uid' => 101, 'name' => 'rango')); $ret = $client->sendMessage($message); var_dump($ret); $transport->close();
<?php namespace picopter\php; error_reporting(E_ALL); require_once '/home/pi/software/thrift-0.9.2/lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = '/home/pi/picopterx/code/src/server/gen-php'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', '/home/pi/software/thrift-0.9.2/lib/php/lib'); $loader->registerDefinition('picopter', $GEN_DIR); $loader->register(); use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\THttpClient; use Thrift\Transport\TBufferedTransport; use Thrift\Exception\TException; try { $socket = new TSocket('localhost', 9090); $transport = new TBufferedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($transport); $client = new \picopter\webInterfaceClient($protocol); $transport->open(); /* ***************************************** */ include 'ajax-functions.php'; /* ***************************************** */ $transport->close(); } catch (TException $tx) { print 'TException: ' . $tx->getMessage() . "\n"; print "Error connecting to flight program."; }
<?php require_once __DIR__ . '/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = dirname(__FILE__) . '/gen-php/'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', __DIR__); $loader->registerDefinition('shared', $GEN_DIR); $loader->registerDefinition('tutorial', $GEN_DIR); $loader->register();
/** * 加载Thrift client */ private function _loadClient() { $loader = new ThriftClassLoader(); //注册命名空间 $loader->registerNamespace('Thrift', $this->t_thrift_path); //注册client service定义 $loader->registerDefinition($this->_t_client, $this->t_client_path); $loader->register(); }
<?php namespace Home\Controller; use Think\Controller; use Think\Log; Vendor('Thrift.ClassLoader.ThriftClassLoader', '', '.php'); Vendor('Thrift', '', '.php'); use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = realpath(dirname(__FILE__)); $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', VENDOR_PATH); $loader->registerDefinition('Thrift', VENDOR_PATH); $loader->register(); use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\THttpClient; use Thrift\Transport\TBufferedTransport; use Thrift\Exception\TException; use Thrift; class DataController extends Controller { private static $client = null; private static function _loadClient() { $socket = new TSocket('182.92.223.200', 9091); $socket->setSendTimeout(20000); $socket->setRecvTimeout(8000000); $transport = new TBufferedTransport($socket); $protocol = new TBinaryProtocol($transport); $transport->open();
<?php namespace picopter\php; error_reporting(E_ALL); require_once '/home/pi/lib/thrift-0.9.0/lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = '/home/pi/picopter/www-waypoints/gen-php'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', '/home/pi/lib/thrift-0.9.0/lib/php/lib'); $loader->registerDefinition('picopter', $GEN_DIR); $loader->register(); use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\THttpClient; use Thrift\Transport\TBufferedTransport; use Thrift\Exception\TException; try { $socket = new TSocket('localhost', 9090); $transport = new TBufferedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($transport); $client = new \picopter\webInterfaceClient($protocol); $transport->open(); /* ***************************************** */ include 'ajax-functions.php'; /* ***************************************** */ $transport->close(); } catch (TException $tx) { //print 'TException: '.$tx->getMessage()."\n"; print "Error connecting to flight program."; }
<?php /** * Created by PhpStorm. * User: nilyang * Date: 15/6/18 * Time: 18:07 */ error_reporting(E_ALL); require_once __DIR__ . '/src/0.9.2/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = realpath(__DIR__ . '/gen-php'); $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', __DIR__ . '/src/0.9.2'); $loader->registerDefinition('Demo', $GEN_DIR); $loader->register(); if (php_sapi_name() == 'cli') { ini_set('display_errors', 'stderr'); } use Demo\AccountIf; use Demo\AccountInfo; class AccountHandler implements AccountIf { /** * @param \Demo\AccountInfo $accountInfo * @return int * @throws \Demo\InvalideOperation */ public function setUserInfo(\Demo\AccountInfo $accountInfo) { echo "log: call " . __METHOD__, "\n\n";
<?php require_once __DIR__ . '/lib/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/lib'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', $GLOBALS['THRIFT_ROOT']); $loader->registerDefinition('shared', $GEN_DIR); $loader->register(); require_once dirname(__FILE__) . '/packages/firtex/ThriftSearchService.php'; require_once dirname(__FILE__) . '/packages/firtex/Types.php'; require_once dirname(__FILE__) . '/packages/firtex/FirteXQueryResult.php'; use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\TFramedTransport; use firtex\ThriftSearchServiceClient; class FirteXRPCClient { public function __construct($host, $port) { try { $socket = new TSocket($host, $port); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport); $transport->open(); $this->_searchService = new ThriftSearchServiceClient($protocol); } catch (TException $tx) { throw FirteXException($tx->getMessage()); } } public function syntaxSearch($uri)
* Licensed under The MIT License * For full copyright and license information, please see the MIT-LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @author walkor<*****@*****.**> * @copyright walkor<*****@*****.**> * @link http://www.workerman.net/ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ use Workerman\Worker; define('THRIFT_ROOT', __DIR__); require_once THRIFT_ROOT . '/Lib/Thrift/ClassLoader/ThriftClassLoader.php'; require_once THRIFT_ROOT . '/Lib/Statistics/StatisticClient.php'; use Thrift\ClassLoader\ThriftClassLoader; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', THRIFT_ROOT . '/Lib'); $loader->registerNamespace('Service', THRIFT_ROOT); $loader->register(); /** * * ThriftWorker * * @author walkor <*****@*****.**> */ class ThriftWorker extends Worker { /** * Thrift processor * @var object */ protected $processor = null;
<?php require_once APPPATH . '/src/lib/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = realpath(dirname(__FILE__)) . '/genphp'; require_once $GEN_DIR . '/NotifyCenter.php'; require_once $GEN_DIR . '/Types.php'; use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\THttpClient; use Thrift\Transport\TBufferedTransport; use Thrift\Exception\TException; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', APPPATH . '/src/lib'); $loader->register();
<?php namespace test\php; require_once __DIR__ . '/../../lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; if (!isset($GEN_DIR)) { $GEN_DIR = 'gen-php'; } if (!isset($MODE)) { $MODE = 'normal'; } $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', __DIR__ . '/../../lib/php/lib'); if ($GEN_DIR === 'gen-php-psr4') { $loader->registerNamespace('ThriftTest', $GEN_DIR); } else { $loader->registerDefinition('ThriftTest', $GEN_DIR); } $loader->register(); /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 *
<?php namespace rpcService; require_once dirname(dirname(__FILE__)) . '/utils/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', dirname(dirname(__FILE__)) . '/utils'); $loader->registerDefinition('thriftrpc', dirname(__FILE__) . '/gen-php'); $loader->register(); use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\THttpClient; use Thrift\Transport\TBufferedTransport; use Thrift\Exception\TException; class RpcService { public function __construct($serverIP, $serverPort, $server = false) { if (!$server) { $this->socket = new TSocket($serverIP, $serverPort); } else { } $this->trans = new TBufferedTransport($this->socket, 1024, 1024); $this->protocol = new TBinaryProtocol($this->trans); $this->client = new \thriftrpc\ThriftRpcClient($this->protocol); $this->trans->open(); } public function smsSend($mobile, $msg) { $this->client->SmsSend($mobile, $msg);
<?php namespace ipquery; define("THRIFT_LIB_DIR", dirname(__FILE__) . "/lib/"); define("IPQUERY_LIB_DIR", dirname(__FILE__)); require_once THRIFT_LIB_DIR . 'Thrift/ClassLoader/ThriftClassLoader.php'; require_once IPQUERY_LIB_DIR . '/Types.php'; require_once IPQUERY_LIB_DIR . '/ipquery.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = realpath(dirname(__FILE__)); $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', THRIFT_LIB_DIR); $loader->register(); use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\THttpClient; use Thrift\Transport\TFramedTransport; use Thrift\Exception\TException; class IpqueryRpcClient { private $client = null; private function init($socket) { $transport = new TFramedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($transport); $this->client = new \ipqueryClient($protocol); $transport->open(); } public function tcpConnect($host, $port) {
<?php error_reporting(E_ALL); // BAD: 写死了路径 require_once '/usr/lib/php/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $GEN_DIR = dirname(__FILE__) . '/gen-php'; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', '/usr/lib/php'); $loader->registerDefinition('Hello', $GEN_DIR); $loader->register(); if (php_sapi_name() == 'cli') { ini_set("display_errors", "stderr"); } use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TPhpStream; use Thrift\Transport\TBufferedTransport; class HelloHandler implements \Hello\HelloServiceIf { public function ping() { error_log("ping()"); } public function hello($name) { return "Hello {$name}"; } public function helloV2(\Hello\Person $person) { return "Hello {$person->firstName}, {$person->lastName}"; }
<?php require_once 'thrift/Thrift/ClassLoader/ThriftClassLoader.php'; use Thrift\ClassLoader\ThriftClassLoader; $loader = new ThriftClassLoader(); $loader->registerNamespace('Thrift', realpath(dirname(__FILE__)) . '/thrift'); $loader->registerDefinition('org\\apache\\hive\\service\\cli\\thrift', realpath(dirname(__FILE__)) . '/hive'); $loader->register(); use Thrift\Type\TType; use Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TSocket; use Thrift\Transport\TBufferedTransport; use org\apache\hive\service\cli\thrift\TCLIServiceClient; use org\apache\hive\service\cli\thrift\TOpenSessionReq; use org\apache\hive\service\cli\thrift\TCloseSessionReq; use org\apache\hive\service\cli\thrift\TExecuteStatementReq; use org\apache\hive\service\cli\thrift\TFetchResultsReq; try { $socket = new TSocket('192.168.0.83', '10000'); $transport = new TBufferedTransport($socket); $protocol = new TBinaryProtocol($transport); // Create a HS2 client $client = new TCLIServiceClient($protocol); // Open up the connection $transport->open(); echo "Opened transport\n"; $sorq = new TOpenSessionReq(); $sorq->username = "******"; $sorq->password = "******"; $rorq = $client->OpenSession($sorq); echo "Opened session\n";