blob: 3ddce304cf1172d3e8e05a573204840de2ac4621 [file] [log] [blame]
Mark Slee06af13d2007-03-21 06:50:52 +00001Thrift PHP/Apache Integration
2
3Author: Mark Slee (mcslee@facebook.com)
4Last Modified: 2007-Mar-20
5
6Thrift is distributed under the Thrift open source software license.
7Please see the included LICENSE file.
8
9Building PHP Thrift Services with Apache
10========================================
11
12Thrift can be embedded in the Apache webserver with PHP installed. Sample
13code is provided below. Note that to make requests to this type of server
14you must use a THttpClient transport.
15
16Sample 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 Sleea821cfd2007-03-21 06:53:03 +000027$GLOBALS['THRIFT_ROOT'] = '/your/thrift/root';
Mark Slee06af13d2007-03-21 06:50:52 +000028
Mark Sleea821cfd2007-03-21 06:53:03 +000029include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
Mark Slee06af13d2007-03-21 06:50:52 +000030include_once $GLOBALS['THRIFT_ROOT'].'/packages/Service/Service.php';
31include_once $GLOBALS['THRIFT_ROOT'].'/transport/TPhpStream.php';
32include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
33
34class ServiceHandler implements ServiceIf {
35 // Implement your interface and methods here
36}
37
38header('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();