16Jan/107
Facebook Thrift PHP Client
A while back I wrote a post about using Facebook's Thrift. One comment asked me to post the PHP client used to connect to the C++ server I was demo'ing. Most of the client is boiler-plate code generated by Thrift, so I chose to omit it at the time. Here it is:
#!/usr/bin/env php <?php $GLOBALS['THRIFT_ROOT'] = '/path/to/thrift'; 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/THttpClient.php'; require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php'; require_once 'Sale.php'; try { $socket = new TSocket('localhost', 9090); $transport = new TBufferedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($transport); $client = new SaleClient($protocol); $transport->open(); $d = new Sale_deal(); $d->dealno = 12345; $d->term = 2; $d->payment = 500.1; $d->amtfin = 1000.00; echo 'Total cost: ' . $client->calc_apr($d) . "\n"; $transport->close(); } catch (TException $tx) { print 'TException: '.$tx->getMessage()."\n"; }
-
andrew
-
http://www.imagehawk.com Mark
-
http://twitter.com/dxdinamic Nikola Petkanski
-
Ed
-
Mladenpetkanski





