blob: 9863aca4f9ce69d5115756cb2b99f1ccef54409d [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 *
Mark Slee06af13d2007-03-21 06:50:52 +000024 */
25
Mark Sleea821cfd2007-03-21 06:53:03 +000026$GLOBALS['THRIFT_ROOT'] = '/your/thrift/root';
Mark Slee06af13d2007-03-21 06:50:52 +000027
Mark Sleea821cfd2007-03-21 06:53:03 +000028include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
Mark Slee06af13d2007-03-21 06:50:52 +000029include_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();