Ejemplo n.º 1
0
error_reporting(E_NONE);
$GEN_DIR = '../gen-php';
require_once $GEN_DIR . '/shared/SharedService.php';
require_once $GEN_DIR . '/shared/shared_types.php';
require_once $GEN_DIR . '/tutorial/Calculator.php';
require_once $GEN_DIR . '/tutorial/tutorial_types.php';
error_reporting(E_ALL);
try {
    if (array_search('--http', $argv)) {
        $socket = new THttpClient('localhost', 8080, '/php/PhpServer.php');
    } else {
        $socket = new TSocket('localhost', 9090);
    }
    $transport = new TBufferedTransport($socket, 1024, 1024);
    $protocol = new TBinaryProtocol($transport);
    $client = new CalculatorClient($protocol);
    $transport->open();
    $client->ping();
    print "ping()\n";
    $sum = $client->add(1, 1);
    print "1+1={$sum}\n";
    $work = new tutorial_Work();
    $work->op = tutorial_Operation::DIVIDE;
    $work->num1 = 1;
    $work->num2 = 0;
    try {
        $client->calculate(1, $work);
        print "Whoa! We can divide by zero?\n";
    } catch (tutorial_InvalidOperation $io) {
        print "InvalidOperation: {$io->why}\n";
    }
Ejemplo n.º 2
0
$GLOBALS['THRIFT_ROOT'] = 'thrift';
// Load up all the thrift stuff
require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TBufferedTransport.php';
// Load the package that we autogenerated for this tutorial
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/calculator/Calculator.php';
// Several things might go wrong
try {
    // Create a thrift connection (Boiler plate)
    $socket = new TSocket('localhost', '9090');
    $transport = new TBufferedTransport($socket);
    $protocol = new TBinaryProtocol($transport);
    // Create a calculator client
    $client = new CalculatorClient($protocol);
    // Open up the connection
    $transport->open();
    // First, lets do something simple
    // Create a simple arithmatic operation (99 / 3)
    $operation = new ArithmeticOperation();
    $operation->op = BinaryOperation::DIVISION;
    $operation->lh_term = 99;
    $operation->rh_term = 3;
    // Perform operation on the server
    $sum = $client->calc($operation);
    print_r($sum);
    // Next, let's create the Matrix:
    //  | 1 2 3 |
    //  | 4 5 6 |
    //  | 7 8 9 |