#apache thrift

Apache Thrift Hello World with PHP and Python Part 2

In the previous post – Apache Thrift Hello World with PHP and Python Part 1, I wrote how to code server python with Apache Thrift. And, the second part, and it is the last one as well, I will show you the way how to writing the client with Laravel 4.2

You could clone full source from here: https://github.com/thanhson1085/thrift-laravel

Please download the source code before reading next steps.

1feac2f8-2d86-11e4-b8e7-12313d026081-medium

What you get by achieving your goals is not nearly as important as what you become by achieving your goals

Step 1: Add Apache Thrift client libraries to Laravel

Create directory: app/libs

Add put all external libraries to that directory.

Includes libraries to Laravel autoload by adding the lib path to composer.json file:

And run composer update :

Step 2: Add a route

Add routes (app/routes.php):

Step 3: Create Hello Controller

Laravel HelloController (HelloController.php):

With source code above, You can see that thrift client will be connect to server at port 9093, localhost, and timeout is 3600 seconds.

Step 4: Run a Test

Run Thrift Server (refer to part 1):

Run client request:

Apache Thrift Hello World with PHP and Python Part 1

In the previous post, I shared you the way how to install Apache Thrift in Ubuntu server. And now, I am writing the first application named Hello World with Apache Thrift in Python and Laravel 4.2

Concept:

You could clone full source from here: https://github.com/thanhson1085/thrift-laravel

Please download the source code before reading next steps.

You never know how strong you are, until being strong is your only choice

You never know how strong you are, until being strong is your only choice

Step 1: Create thrift files hello.thirft and exceptions.thrift

hello.thrift:

exceptions.thrift:

Step 2:  Run thrift compiler command to generate source code

See the details at gen.sh file

Step 3: Code the server-side

Code Hello Server hello-server.py (located src/python directory):

Create Hander hander.py located in src/python/hello:

Step 4: Run a test

Finally, test the server with server.sh script:

The output will be as below:

That means that you created server-side successfully.

Please keep reading Part 2 to know how to code the client-side with PHP Laravel 4.2

 

Install Apache Thrift from source in Ubuntu 14.04

Apache Thrift helps you build scalable cross-language services.  It supports C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml. It is really helpful if you want to scale your system base on HTTP protocol. And the below is a tutorial help you are able install Apache Thrift in Ubuntu 14.04.

Actually, It is easily to install it with command:

But with building from source code, there is more complicate than that. See the below.

Preparing libraries:

Install JAVA:

Clone Thrift source and make install:

Testing: