blob: fdd12ac5b3ca4130519216386fdfd06219999ca2 [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
Mark Slee07a3aab2007-03-07 05:45:10 +000027try {
Mark Slee76791962007-03-14 02:47:35 +000028 $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 Slee07a3aab2007-03-07 05:45:10 +000067}
68
Mark Slee07a3aab2007-03-07 05:45:10 +000069?>