示例#1
0
 /**
  * Register alias load.
  */
 private function register()
 {
     $loader = new ThriftClassLoader();
     foreach ($this->definitions as $alias => $path) {
         $loader->registerDefinition($alias, $this->path . $path);
     }
     $loader->register();
 }
示例#2
0
 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;
     }
 }
示例#3
0
 /**
  * 加载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();
 }
示例#4
0
 public function __get($name)
 {
     if (!isset($this->serviceConfig[$name]) || !is_array($this->serviceConfig[$name]) || !isset($this->serviceConfig[$name]['clientName'])) {
         throw new \Exception('参数配置错误');
     }
     $config = $this->serviceConfig[$name];
     $loader = new ThriftClassLoader();
     // 当前service的cient类名(包含全部命名空间)
     $clientName = $config['clientName'];
     $defineName = explode('\\', ltrim($clientName, '\\'))[0];
     $loader->registerDefinition($defineName, $this->genDir);
     if (!empty($config['defineName'])) {
         if (is_string($config['defineName'])) {
             $loader->registerDefinition($config['defineName'], $this->genDir);
         } elseif (is_array($config['defineName'])) {
             foreach ($config['defineName'] as $item) {
                 $loader->registerDefinition($item, $this->genDir);
             }
         }
     }
     $loader->register();
     // 如果有单独配置则使用单独配置,否则使用全局配置
     $host = isset($config['host']) ? $config['host'] : $this->host;
     $port = isset($config['port']) ? $config['port'] : $this->port;
     $uri = isset($config['uri']) ? $config['uri'] : $this->uri;
     $rBufSize = isset($config['rBufSize']) ? $config['rBufSize'] : $this->rBufSize;
     $wBufSize = isset($config['wBufSize']) ? $config['wBufSize'] : $this->wBufSize;
     $transportName = '\\Thrift\\Transport\\' . (isset($config['transportName']) ? $config['transportName'] : $this->transportName);
     $protocolName = '\\Thrift\\Protocol\\' . (isset($config['protocolName']) ? $config['protocolName'] : $this->protocolName);
     if ((isset($config['requestType']) ? $config['requestType'] : $this->requestType) == 'http') {
         $httpName = '\\Thrift\\Transport\\' . (isset($config['httpName']) ? $config['httpName'] : $this->httpName);
         $this->socket = new $httpName($host, $port, $uri);
     } else {
         $socketName = '\\Thrift\\Transport\\' . (isset($config['socketName']) ? $config['socketName'] : $this->socketName);
         $this->socket = new $socketName($host, $port);
     }
     $this->transport = new $transportName($this->socket, $rBufSize, $wBufSize);
     $this->protocol = new $protocolName($this->transport);
     $this->transport->open();
     $this->{$name} = new $clientName($this->protocol);
     return $this->{$name};
 }
示例#5
0
 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('');
 }
示例#6
0
 /**
  * Register the definitions with the Thrift class loader.
  */
 protected function register()
 {
     // use loader only for definitions, base class should use the Composer loader
     $loader = new ThriftClassLoader();
     // load Thrift definitions
     if (is_array($this->definitions)) {
         foreach ($this->definitions as $dnamespace => $dpath) {
             if (is_numeric($dnamespace)) {
                 $dnamespace = $dpath;
                 $dpath = '';
             }
             $curPath = $this->genPath;
             if ($dpath != '') {
                 $curPath .= '/' . $dpath;
             }
             $loader->registerDefinition($dnamespace, Yii::getAlias($curPath));
         }
     }
     // Yii autoloader must be last
     spl_autoload_unregister(['Yii', 'autoload']);
     $loader->register();
     spl_autoload_register(['Yii', 'autoload'], true, true);
 }
示例#7
0
<?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

/**
 * 
 * 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()
<?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;
示例#10
0
<?php

namespace ThriftClient;

require_once __DIR__ . '/../Thrift/ClassLoader/ThriftClassLoader.php';
use Thrift\ClassLoader\ThriftClassLoader;
$GEN_DIR = realpath(dirname(__FILE__)) . '/gen-php';
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/..');
$loader->registerDefinition('cbm', $GEN_DIR);
$loader->registerDefinition('ctrl', $GEN_DIR);
$loader->register();
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
// use Thrift\Transport\THttpClient;
use Thrift\Transport\TBufferedTransport;
use Thrift\Exception\TException;
// require_once __DIR__.'/gen-php/cbm/CbmService.php';
// require_once __DIR__.'/gen-php/cbm/Types.php';
define('HOST', 'localhost');
define('PORT1', 9100);
define('PORT2', 9090);
class ThriftClient
{
    public $client;
    private $transport;
    private $protocol;
    private $client_class;
    private $server_ip;
    private $server_port;
    private $socket;
示例#11
0
#!/usr/bin/env php
<?php 
namespace tutorial\php;

error_reporting(E_ALL);
require_once __DIR__ . '/../../lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php';
use Thrift\ClassLoader\ThriftClassLoader;
$GEN_DIR = realpath(dirname(__FILE__) . '/..') . '/gen-php';
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/../../lib/php/lib');
$loader->registerDefinition('shared', $GEN_DIR);
$loader->registerDefinition('tutorial', $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.
 */
示例#12
0
<?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');
$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
 *
 * 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
示例#13
0
<?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.
示例#14
0
文件: client.php 项目: higherchen/rpc
<?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();
示例#15
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.
 *
 * @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()
    {
示例#16
0
<?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)
示例#17
0
<?php

namespace TTG;

error_reporting(E_ALL);
require_once __DIR__ . '/Thrift/ClassLoader/ThriftClassLoader.php';
require_once __DIR__ . '/Gen/TTGService.php';
require_once __DIR__ . '/Gen/Types.php';
use Thrift\ClassLoader\ThriftClassLoader;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TBufferedTransport;
// Load
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/');
$loader->registerDefinition('TTG', __DIR__ . '/Gen');
$loader->register();
// Init
$socket = new TSocket('127.0.0.1', 9090);
$transport = new TBufferedTransport($socket, 1024, 1024);
$protocol = new TBinaryProtocol($transport);
$client = new TTGServiceClient($protocol);
// Config
$socket->setSendTimeout(30 * 1000);
$socket->setRecvTimeout(30 * 1000);
// Connect
$transport->open();
// Create request
$request = new Request();
$request->studentID = 100;
// Call...
<?php

error_reporting(E_ALL);
include 'vendor/autoload.php';
use Thrift\ClassLoader\ThriftClassLoader;
$GEN_DIR = realpath(dirname(__FILE__)) . '/gen-php';
$loader = new ThriftClassLoader();
$loader->registerDefinition('petrabarus', $GEN_DIR);
$loader->register();
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\THttpClient;
use Thrift\Transport\TBufferedTransport;
use Thrift\Exception\TException;
$socket = new THttpClient('localhost', 80);
$transport = new TBufferedTransport($socket, 1024, 1024);
$protocol = new TBinaryProtocol($transport);
$client = new petrabarus\services\HelloServiceClient($protocol);
$transport->open();
echo $client->say_hello();
print_r($client->say_hello_repeat(4));
echo $client->say_foreign_hello(petrabarus\services\HelloLanguage::SPANISH);
示例#19
0
 *
 * 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 
     */
示例#20
0
<?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

$time_start = microtime(true);
$GLOBALS['THRIFT_ROOT'] = '/usr/lib/php';
$GLOBALS['SCRIBE_ROOT'] = '/home/trangntb/testphpextension/gen-php';
error_reporting(E_ALL);
require_once '/usr/lib/php/Thrift/ClassLoader/ThriftClassLoader.php';
use Thrift\ClassLoader\ThriftClassLoader;
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', '/usr/lib/php/');
$loader->register();
include_once $GLOBALS['SCRIBE_ROOT'] . '/facebook/fb303/FacebookService.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Type/TType.php';
include_once $GLOBALS['SCRIBE_ROOT'] . '/scribe/thrift/Types.php';
include_once $GLOBALS['SCRIBE_ROOT'] . '/scribe/thrift/scribe.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Protocol/TProtocol.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Protocol/TBinaryProtocol.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TTransport.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TFramedTransport.php';
include_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TSocket.php';
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TFramedTransport;
use Thrift\Exception\TException;
use scribe\thrift\scribeClient;
use scribe\thrift\LogEntry;
use scribe\thrift\ResultCode;
try {
    $sock = new TSocket('localhost', 1463);
    $trans = new TFramedTransport($sock);
    $prot = new TBinaryProtocol($trans);
示例#22
0
<?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)
    {
示例#23
0
<?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();
示例#24
0
 * 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.
 */
namespace test\php;

require_once __DIR__ . '/../../../lib/Thrift/ClassLoader/ThriftClassLoader.php';
use Thrift\ClassLoader\ThriftClassLoader;
use Thrift\Exception\TProtocolException;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TMemoryBuffer;
$oop_mode = isset($argv[1]) && $argv[1] === '-oop';
$GEN_DIR = $oop_mode ? 'phpvo' : 'phpv';
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/../../../lib');
$loader->registerDefinition('ThriftTest', __DIR__ . '/../../packages/' . $GEN_DIR);
$loader->registerDefinition('TestValidators', __DIR__ . '/../../packages/' . $GEN_DIR);
$loader->register();
// Would be nice to have PHPUnit here, but for now just hack it.
set_exception_handler(function ($e) {
    my_assert(false, "Unexpected exception caught: " . $e->getMessage());
});
set_error_handler(function ($errno, $errmsg) {
    my_assert(false, "Unexpected PHP error: " . $errmsg);
});
// Empty structs should not have validators
assert_has_no_read_validator('ThriftTest\\EmptyStruct');
assert_has_no_write_validator('ThriftTest\\EmptyStruct');
assert_has_no_read_validator('ThriftTest\\Bonk');
示例#25
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);
示例#26
0
#!/usr/bin/env php
<?php 
namespace tutorial\php;

error_reporting(E_ALL);
require_once __DIR__ . '/../Thrift/ClassLoader/ThriftClassLoader.php';
use Thrift\ClassLoader\ThriftClassLoader;
$GEN_DIR = realpath(dirname(__FILE__) . '/..') . '/gen-php';
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/../');
$loader->registerDefinition('demo', $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 DemoHandler implements \demo\FooIf
{
    public function getUserInfo($uid)
    {
        return new \demo\User(array('uid' => $uid, 'name' => 'name', 'age' => 18));
    }
}
header('Content-Type', 'application/x-thrift');
if (php_sapi_name() == 'cli') {
    echo "\r\n";
}
$handler = new DemoHandler();
$processor = new \demo\FooProcessor($handler);
示例#27
0
<?php

namespace imweb\php;

//error_reporting(0);
//ip白名单
$white_ip_array = array('127.0.0.1', '172.16.43.113', '172.19.31.70', '119.97.153.227', '183.60.177.224/27', '210.21.125.40/29', '113.108.232.33', '113.108.232.34', '183.61.143.34');
require_once __DIR__ . '/Thrift/ClassLoader/ThriftClassLoader.php';
use Thrift\ClassLoader\ThriftClassLoader;
$GEN_DIR = realpath(dirname(__FILE__)) . '/gen-php/';
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/');
$loader->registerDefinition('mobilemsg', $GEN_DIR);
$loader->register();
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TSocketPool;
use Thrift\Transport\THttpClient;
use Thrift\Transport\TFramedTransport;
use Thrift\Exception\TException;
function check_ip($ip_array = array(), $remote_ip = '')
{
    $remote_ip = empty($remote_ip) ? $_SERVER['REMOTE_ADDR'] : $remote_ip;
    //判断ip是否在白名单
    foreach ($ip_array as $ip) {
        $ip_info = explode('/', $ip);
        $mask = isset($ip_info[1]) ? $ip_info[1] : 32;
        if (substr(sprintf("%032b", ip2long($ip_info[0])), 0, $mask) === substr(sprintf("%032b", ip2long($remote_ip)), 0, $mask)) {
            return true;
        }
    }
示例#28
0
echo "Upload: " . $filename . "<br>";
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);
示例#29
0
<?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}";
    }
示例#30
0
<?php

namespace Simcu\Thrift;

/**
 * Created by IntelliJ IDEA.
 * User: xRain
 * Date: 16/6/10
 * Time: 19:03
 */
use Workerman\Worker;
use Thrift\ClassLoader\ThriftClassLoader;
$loader = new ThriftClassLoader();
$loader->register();
/**
 *
 *  ThriftWorker
 *
 * @author walkor <*****@*****.**>
 */
class Server extends Worker
{
    /**
     * Thrift processor
     * @var object
     */
    protected $processor = null;
    /**
     * 使用的协议,默认TBinaryProtocol,可更改
     * @var string
     */