RPC Framework-yar Learning

Source: Internet
Author: User
Tags class operator

RPC takes client/server mode. The requestor is a client, and the service provider is a server. First, the client call process sends a call message with process parameters to the service process, and then waits for the reply message. On the server side, the process stays asleep until the call information arrives. When a call arrives, the server obtains the process parameters, evaluates the result, sends a reply message, and then waits for the next invocation information, and finally, the client invokes the process to receive the reply message, obtains the process result, and then invokes execution to proceed.

PHP simple framework of RPC feel is Yar, try to write a case, in advance need to install the Yar framework, specific installation methods online Search:

Server-side: Address: http://html.com/yar/Operator.php code:

Class Operator {    /**     * add \ Operands     * @param interge      * @return interge * * Public    function add ($a, $b) {        return $this->_add ($a, $b);    }    /**     * Sub      *    /Public Function Sub ($a, $b) {        return $a-$b;    }    /** * Mul * * * public    function Mul ($a, $b) {        return $a * $b;    }    /**     * Protected methods won't be exposed     * @param interge      * @return Interge *     /    Protected func tion _add ($a, $b) {        return $a + $b;    }} $server = new Yar_server (new Operator ()); $server->handle ();

Customer's address: http://html.com/yar/yar.php

Code:

$url = "http://html.com/yar/Operator.php"; $client = new Yar_client ($url); Var_dump ($client->add (1, 2)); Var_dump ($ Client->call ("Add", Array (3, 2)));

Printing results are:

Int (3) int (5)



RPC Framework-yar Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.