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