blob: 04362c21107c0b640e23d227a79f91581a86c856 [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
27$GLOBALS['THRIFT_ROOT'] = '/your/thrift/root/';
28
29include_once $GLOBALS['THRIFT_ROOT'].'/packages/Service/Service.php';
30include_once $GLOBALS['THRIFT_ROOT'].'/transport/TPhpStream.php';
31include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
32
33class ServiceHandler implements ServiceIf {
34 // Implement your interface and methods here
35}
36
37header('Content-Type: application/x-thrift');
38
39$handler = new ServiceHandler();
40$processor = new ServiceProcessor($handler);
41
42// Use the TPhpStream transport to read/write directly from HTTP
43$transport = new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W);
44$protocol = new TBinaryProtocol($transport);
45
46$transport->open();
47$processor->process($protocol, $protocol);
48$transport->close();