blob: ca4f50d3bb68649fce7d82455b940b3307d2ccb8 [file] [log] [blame]
Mark Slee07a3aab2007-03-07 05:45:10 +00001#!/usr/bin/env php
2<?php
3
4$GLOBALS['THRIFT_ROOT'] = '../../lib/php/src';
5
6require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
7require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
8require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
9require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
10
11/**
12 * Suppress errors in here, which happen because we have not installed into
13 * $GLOBALS['THRIFT_ROOT'].'/packages/tutorial' like we are supposed to!
14 *
15 * Normally we would only have to include Calculator.php which would properly
16 * include the other files from their packages/ folder locations, but we
17 * include everything here due to the bogus path setup.
18 */
19error_reporting(E_NONE);
20$GEN_DIR = '../gen-php';
21require_once $GEN_DIR.'/SharedService.php';
22require_once $GEN_DIR.'/shared_types.php';
23require_once $GEN_DIR.'/Calculator.php';
24require_once $GEN_DIR.'/tutorial_types.php';
25error_reporting(E_ALL);
26
27$socket = new TSocket('localhost', 9090);
28$transport = new TBufferedTransport($socket, 1024, 1024);
29$protocol = new TBinaryProtocol($transport);
30$client = new CalculatorClient($protocol);
31
32$transport->open();
33
34$client->ping();
35print "ping()\n";
36
37$sum = $client->add(1,1);
38print "1+1=$sum\n";
39
40$work = new tutorial_Work();
41
42$work->op = tutorial_Operation::DIVIDE;
43$work->num1 = 1;
44$work->num2 = 0;
45
46try {
47 $client->calculate(1, $work);
48 print "Whoa! We can divide by zero?\n";
49} catch (tutorial_InvalidOperation $io) {
50 print "InvalidOperation: $io->why\n";
51}
52
53$work->op = tutorial_Operation::SUBTRACT;
54$work->num1 = 15;
55$work->num2 = 10;
56$diff = $client->calculate(1, $work);
57print "15-10=$diff\n";
58
59$log = $client->getStruct(1);
60print "Log: $log->value\n";
61
62$transport->close();
63
64?>