Mark Slee | 06af13d | 2007-03-21 06:50:52 +0000 | [diff] [blame] | 1 | Thrift PHP/Apache Integration |
| 2 | |
| 3 | Author: Mark Slee (mcslee@facebook.com) |
| 4 | Last Modified: 2007-Mar-20 |
| 5 | |
| 6 | Thrift is distributed under the Thrift open source software license. |
| 7 | Please see the included LICENSE file. |
| 8 | |
| 9 | Building PHP Thrift Services with Apache |
| 10 | ======================================== |
| 11 | |
| 12 | Thrift can be embedded in the Apache webserver with PHP installed. Sample |
| 13 | code is provided below. Note that to make requests to this type of server |
| 14 | you must use a THttpClient transport. |
| 15 | |
| 16 | Sample Code |
| 17 | =========== |
| 18 | |
| 19 | <?php |
| 20 | |
| 21 | /** |
| 22 | * Example of how to build a Thrift server in Apache/PHP |
| 23 | * |
| 24 | * @author Mark Slee <mcslee@facebook.com> |
| 25 | */ |
| 26 | |
Mark Slee | a821cfd | 2007-03-21 06:53:03 +0000 | [diff] [blame] | 27 | $GLOBALS['THRIFT_ROOT'] = '/your/thrift/root'; |
Mark Slee | 06af13d | 2007-03-21 06:50:52 +0000 | [diff] [blame] | 28 | |
Mark Slee | a821cfd | 2007-03-21 06:53:03 +0000 | [diff] [blame] | 29 | include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php'; |
Mark Slee | 06af13d | 2007-03-21 06:50:52 +0000 | [diff] [blame] | 30 | include_once $GLOBALS['THRIFT_ROOT'].'/packages/Service/Service.php'; |
| 31 | include_once $GLOBALS['THRIFT_ROOT'].'/transport/TPhpStream.php'; |
| 32 | include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php'; |
| 33 | |
| 34 | class ServiceHandler implements ServiceIf { |
| 35 | // Implement your interface and methods here |
| 36 | } |
| 37 | |
| 38 | header('Content-Type: application/x-thrift'); |
| 39 | |
| 40 | $handler = new ServiceHandler(); |
| 41 | $processor = new ServiceProcessor($handler); |
| 42 | |
| 43 | // Use the TPhpStream transport to read/write directly from HTTP |
| 44 | $transport = new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W); |
| 45 | $protocol = new TBinaryProtocol($transport); |
| 46 | |
| 47 | $transport->open(); |
| 48 | $processor->process($protocol, $protocol); |
| 49 | $transport->close(); |