Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 1 | #!/usr/bin/env php |
| 2 | <?php |
| 3 | |
| 4 | $GLOBALS['THRIFT_ROOT'] = '../../lib/php/src'; |
| 5 | |
| 6 | require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php'; |
| 7 | require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php'; |
| 8 | require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php'; |
| 9 | require_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 | */ |
| 19 | error_reporting(E_NONE); |
| 20 | $GEN_DIR = '../gen-php'; |
| 21 | require_once $GEN_DIR.'/SharedService.php'; |
| 22 | require_once $GEN_DIR.'/shared_types.php'; |
| 23 | require_once $GEN_DIR.'/Calculator.php'; |
| 24 | require_once $GEN_DIR.'/tutorial_types.php'; |
| 25 | error_reporting(E_ALL); |
| 26 | |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 27 | try { |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame^] | 28 | $socket = new TSocket('localhost', 9090); |
| 29 | $transport = new TBufferedTransport($socket, 1024, 1024); |
| 30 | $protocol = new TBinaryProtocol($transport); |
| 31 | $client = new CalculatorClient($protocol); |
| 32 | |
| 33 | $transport->open(); |
| 34 | |
| 35 | $client->ping(); |
| 36 | print "ping()\n"; |
| 37 | |
| 38 | $sum = $client->add(1,1); |
| 39 | print "1+1=$sum\n"; |
| 40 | |
| 41 | $work = new tutorial_Work(); |
| 42 | |
| 43 | $work->op = tutorial_Operation::DIVIDE; |
| 44 | $work->num1 = 1; |
| 45 | $work->num2 = 0; |
| 46 | |
| 47 | try { |
| 48 | $client->calculate(1, $work); |
| 49 | print "Whoa! We can divide by zero?\n"; |
| 50 | } catch (tutorial_InvalidOperation $io) { |
| 51 | print "InvalidOperation: $io->why\n"; |
| 52 | } |
| 53 | |
| 54 | $work->op = tutorial_Operation::SUBTRACT; |
| 55 | $work->num1 = 15; |
| 56 | $work->num2 = 10; |
| 57 | $diff = $client->calculate(1, $work); |
| 58 | print "15-10=$diff\n"; |
| 59 | |
| 60 | $log = $client->getStruct(1); |
| 61 | print "Log: $log->value\n"; |
| 62 | |
| 63 | $transport->close(); |
| 64 | |
| 65 | } catch (TException $tx) { |
| 66 | print 'TException: '.$tx->getMessage()."\n"; |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 69 | ?> |