自 11 月后端結(jié)構(gòu)調(diào)整正式啟動已有月余料滥,效果初現(xiàn)然眼;
PHP Yar(Yet Another RPC Framework)是我們采取的措施之一;
版本 1.3 開發(fā)過程中葵腹,Yar 服務(wù) 5XX 錯誤頻頻高每,問題解決速度遠低于期望;
調(diào)試(Debug)技術(shù)践宴、測試技術(shù)鲸匿、觀測手段的匱乏,恐怕是其中最大的原因之一阻肩;
源于超人在 PHPUnit 上的 最新嘗試带欢,我們試圖在這方面上一個臺階:高質(zhì)量的敏捷交付运授;
RPC(Remote Procedure Calling) Mechanism
- 示意圖由 Dave Marshall 提供;
A remote procedure is uniquely identified by the triple: (program number, version number, procedure number) The program number identifies a group of related remote procedures, each of which has a unique procedure number. A program may consist of one or more versions. Each version consists of a collection of procedures which are available to be called remotely. Version numbers enable multiple versions of an RPC protocol to be available simultaneously. Each version contains a a number of procedures that can be called remotely. Each procedure has a procedure number.
Yar 在 GitHub
Yar is a RPC framework which aims to provide a simple and easy way to do communication between PHP applications.
It has the ability to concurrently call multiple remote services.
- 是一個 PECL 擴展乔煞,屬于 Web Service 分類吁朦;
- 采用 HTTP 協(xié)議傳輸數(shù)據(jù);
- 多種 data packager:php渡贾,json逗宜,msgpack;
msgpack 需要單獨安裝擴展空骚; -
Runtime Configure
示例
- yarserver.php
<?php
class API {
public function testName($name) {
error_log("Hello, $name\n", 3, "/logs/yar.log");
return "Hello, $name";
}
public function testAdd($a, $b) {
$c = $a + $b;
error_log("$a + $b = $c\n", 3, "/logs/yar.log");
return "$a + $b = $c";
}
}
$service = new Yar_Server(new API());
$service->handle();
- yarserver.php @ api.example.com
- yarclient.php
<?php
$client = new Yar_Client("http://api.example.com/yarserver.php");
echo $client->testName("michael");
echo $client->testAdd(2,3);
- yarclient.php @ www.example.com
如何對 RPC 服務(wù)進行單獨測試纺讲?
- ?
關(guān)于 gRPC
Google 名下的開源項目府怯;
-
gRPC Concepts刻诊;
Like many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. By default, gRPC uses protocol buffers as the Interface Definition Language (IDL) for describing both the service interface and the structure of the payload messages. - A Basic PHP Programmer’s Introduction to Working with gRPC;
- Why use gRPC?
With gRPC you can define your service once in a .proto file and implement clients and servers in any of gRPC’s supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. You also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL(Interface Definition Language), and easy interface updating. -
Protocol Buffers - Google's data interchange format.
Protocol Buffers (a.k.a., protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. You can find protobuf's documentation on the Google Developers site. -
Protocol Buffers are similar to the Apache Thrift (used by Facebook) or Microsoft Bond protocols.
Comparison of data serialization formats. - gRPC library for PHP牺丙;
- SOA则涯,SOA Reference Model;
- HTTP Status Code 499
HTTP 499 in Nginx means that the client closed the connection before the server answered the request. In my experience it is usually caused by client side timeout. As I know it's an Nginx specific error code.
https://gist.github.com/dzlab/2e6e79419877dc29d2efc63ae5974fd5
https://danielmiessler.com/blog/log-post-data-nginx/#gs.ZM_5pEY
http://developers.redhat.com/blog/2016/05/23/configuring-nginx-to-log-post-data-on-linux-rhel/
http://stackoverflow.com/questions/4939382/logging-post-data-from-request-body
https://laracasts.com/discuss/channels/general-discussion/laravel-and-rpc
http://restfulapi.nl/#what1
http://www.jsonrpc.org/
https://miniflux.net/documentation/json-rpc-api
http://pages.cs.wisc.edu/~remzi/OSTEP/dist-intro.pdf