10

I already have a web server that I pay for, and I want to expose some services on it using Thrift and PHP.

My question is: can I run a Thrift server using normal PHP that's hosted on the default port (the same way web pages are hosted) instead of having a separate PHP application that runs on some funky obscure port. This way I wouldn't have to change the server configuration (which is something I'm not able to do even if I wanted to).

Thanks

EDIT: maybe I should clarify a bit more. Once I've defined my service using a .thrift file, is it possible to:

  1. Run the thrift code generator
  2. Take the generated code and put it on my webserver
  3. Create an index.php which says (in pseudocode) "create a new instance of the service, and handle incoming requests"?
Will Warren
  • 1,264
  • 14
  • 32
  • I'm not sure if this needs to be closed or what, but it has been answered. – Will Warren Jan 18 '12 at 18:02
  • a bit late I know, but in reply to your comment, the usual way of dealing with it would be to post the answer yourself below, and then mark it as accepted. By the way, thank you for the link -- very helpful. If only the Thrift website itself had any kind of useful info.... :-/ – SDC May 29 '12 at 14:33
  • Thanks for the tip, have done so. Also added a link to my blog where I wrote up a simple example. – Will Warren May 30 '12 at 15:23
  • awesome, thankyou. I'm sure I'll be spending some time there. Oh, and I've given your answer +1 because it's useful. :) – SDC May 30 '12 at 15:48

1 Answers1

12

Okay, well I have figured out the answer on my own!

If you use a TPhpStream on the server side, you are able to serve requests coming in as regular http requests.

Many thanks to Rob Wilkerson https://github.com/robwilkerson/Thrift-Client-Server-Example--PHP-.

I also blogged about how to implement a simple example with PHP and Python at http://willwarren.com/2012/01/24/creating-a-public-api-with-apache-thrift/

Will Warren
  • 1,264
  • 14
  • 32