blob: 8c41833d10fa3c1b9c2af6ff7847437299a259ac [file] [log] [blame]
Mark Slee06af13d2007-03-21 06:50:52 +00001Thrift PHP/Apache Integration
2
Bryan Duxburydef30a62009-04-08 00:19:37 +00003License
4=======
5
6Licensed to the Apache Software Foundation (ASF) under one
7or more contributor license agreements. See the NOTICE file
8distributed with this work for additional information
9regarding copyright ownership. The ASF licenses this file
10to you under the Apache License, Version 2.0 (the
11"License"); you may not use this file except in compliance
12with the License. You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16Unless required by applicable law or agreed to in writing,
17software distributed under the License is distributed on an
18"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19KIND, either express or implied. See the License for the
20specific language governing permissions and limitations
21under the License.
Mark Slee06af13d2007-03-21 06:50:52 +000022
23Building PHP Thrift Services with Apache
24========================================
25
26Thrift can be embedded in the Apache webserver with PHP installed. Sample
27code is provided below. Note that to make requests to this type of server
28you must use a THttpClient transport.
29
30Sample Code
31===========
32
33<?php
34
35/**
36 * Example of how to build a Thrift server in Apache/PHP
37 *
Mark Slee06af13d2007-03-21 06:50:52 +000038 */
39
Mark Sleea821cfd2007-03-21 06:53:03 +000040$GLOBALS['THRIFT_ROOT'] = '/your/thrift/root';
Mark Slee06af13d2007-03-21 06:50:52 +000041
Mark Sleea821cfd2007-03-21 06:53:03 +000042include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
Mark Slee06af13d2007-03-21 06:50:52 +000043include_once $GLOBALS['THRIFT_ROOT'].'/packages/Service/Service.php';
44include_once $GLOBALS['THRIFT_ROOT'].'/transport/TPhpStream.php';
45include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
46
47class ServiceHandler implements ServiceIf {
48 // Implement your interface and methods here
49}
50
51header('Content-Type: application/x-thrift');
52
53$handler = new ServiceHandler();
54$processor = new ServiceProcessor($handler);
55
56// Use the TPhpStream transport to read/write directly from HTTP
57$transport = new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W);
58$protocol = new TBinaryProtocol($transport);
59
60$transport->open();
61$processor->process($protocol, $protocol);
62$transport->close();