Objective
A project, from start to release update, is maintained until the final version. Functions are increasing, the corresponding code volume is also increasing, it means that the project becomes more non-maintainable, at this time, we need to split the way to break up a project, so that the development team to better maintain the project.
Sub-module
This stage, is generally also the initial stage of the project, due to insufficient manpower, a service-side interface project only one development for maintenance, according to the habit of development, the project will be divided into several modules for development, under a project deployment.
The disadvantage of this is that the project becomes non-maintainable as the version is updated.
Sub-item
As the functionality of each module continues to evolve, the code becomes more bloated. At this time the project needs to be split, such as the above diagram, divided into user system projects, payment system projects.
CURL
You'll start by using curl to access external resources.
For example, a message Platform SDK, such as the major third-party provided by the SDK, tangled to source discovery is directly using the Curl function to access the way.
The advantage is that there is no environmental requirement and can be used directly.
The disadvantage is the resource consumption problem of concurrent access.
//Sina Weibo SDK http request part of the source code /** * Make an HTTP request * * @return string API results * @ignore * / function http($url, $method, $postfields = NULL, $headers = array()) { $this->http_info =Array();$ci= Curl_init ();/ * Curl settings * /curl_setopt ($ci, Curlopt_http_version, CURL_HTTP_VERSION_1_0); curl_setopt ($ci, Curlopt_useragent,$this->useragent); curl_setopt ($ci, Curlopt_connecttimeout,$this->connecttimeout); curl_setopt ($ci, Curlopt_timeout,$this->timeout); curl_setopt ($ci, Curlopt_returntransfer,TRUE); curl_setopt ($ci, Curlopt_encoding,""); curl_setopt ($ci, Curlopt_ssl_verifypeer,$this->ssl_verifypeer);if(Version_compare (Phpversion (),' 5.4.0 ',' < ') {curl_setopt ($ci, Curlopt_ssl_verifyhost,1); }Else{curl_setopt ($ci, Curlopt_ssl_verifyhost,2); } curl_setopt ($ci, Curlopt_headerfunction,Array($this,' GetHeader ')); curl_setopt ($ci, Curlopt_header,FALSE);Switch($method) { Case ' POST ': curl_setopt ($ci, Curlopt_post,TRUE);if(!Empty($postfields) {curl_setopt ($ci, Curlopt_postfields,$postfields);$this->postdata =$postfields; } Break; Case ' DELETE ': curl_setopt ($ci, Curlopt_customrequest,' DELETE ');if(!Empty($postfields)) {$url="{$url}?" {$postfields} "; } }if(isset($this->access_token) &&$this->access_token)$headers[] ="Authorization:oauth2".$this->access_token;if( !Empty($this->REMOTE_IP)) {if(Defined (' Sae_accesskey ') ) {$headers[] ="SAEREMOTEIP:".$this->remote_ip; }Else{$headers[] ="API-REMOTEIP:".$this->remote_ip; } }Else{if(!defined (' Sae_accesskey ') ) {//$headers [] = "API-REMOTEIP:". $_server[' REMOTE_ADDR '];}} curl_setopt ($ci, Curlopt_url,$url); curl_setopt ($ci, Curlopt_httpheader,$headers); curl_setopt ($ci, Curlinfo_header_out,TRUE);$response= Curl_exec ($ci);$this->http_code = Curl_getinfo ($ci, Curlinfo_http_code);$this->http_info = Array_merge ($this->http_info, Curl_getinfo ($ci));$this->url =$url;if($this->debug) {Echo "=====post data======\r\n"; Var_dump ($postfields);Echo "=====headers======\r\n"; Print_r ($headers);Echo ' =====request info===== '."\ r \ n"; Print_r (Curl_getinfo ($ci) );Echo ' =====response===== '."\ r \ n"; Print_r ($response); } curl_close ($ci);return $response; }
Rpc
Remote Procedure Call Protocol
RPC (remote Procedure call Protocol)-a remoting protocol that requests services from a remote computer program over a network without needing to know the underlying network technology. The RPC protocol assumes that some transport protocols exist, such as TCP or UDP, to carry information data between communication programs. In the OSI network communication model, RPC spans the transport and application tiers. RPC makes it easier to develop applications that include distributed, multi-program networks.
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.
Yar
Bird Brother produced the RPC framework, lightweight framework.
<?php class API { /** * The DOC info would be generated automatically into service info page. * @params * @return * * Public function API($parameter, $option = "foo") {}protected function client_can_not_see() {}}$service=NewYar_server (NewAPI ());$service->handle ();?>
Calling code
<?php$clientnew Yar_Client("http://host/api/");$result$client->api("parameter);?>
Note that the bird brother out of something less documents, need more debugging.
Thrift
Thrift is a software framework for the development of extensible, cross-language services. It combines a powerful software stack and code generation engine to build in C + +, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C #, Cocoa, JavaScript, node. js, Smalltalk, and OCaml the seamless and efficient service between these programming languages.
The meaning of remote invocation is that different sub-projects can be solved in a more appropriate language and more efficient implementation of the requirements.
At the same time, for the development of the team, it can improve the overall technical level.
Soap
Because the XML used is not much described, after all, it is still more json.
Json-rpc
The following is the standard for return values
- [{"Jsonrpc":"2.0","Method":"Sum","params": [1,2,4],"id":"1"}, {"Jsonrpc":"2.0","Method":"Notify_hello","params": [7]}, {"Jsonrpc":"2.0","Method":"Subtract","params": [ the, at],"id":"2"}, {"foo":"Boo"}, {"Jsonrpc":"2.0","Method":"Foo.get","params": {"Name":"Myself"},"id":"5"}, {"Jsonrpc":"2.0","Method":"Get_data","id":"9"}]<-- [{"Jsonrpc":"2.0","Result":7,"id":"1"}, {"Jsonrpc":"2.0","Result": +,"id":"2"}, {"Jsonrpc":"2.0","Error": {"Code": -32600,"Message":"Invalid Request"},"id":NULL}, {"Jsonrpc":"2.0","Error": {"Code": -32601,"Message":"Method not Found"},"id":"5"}, {"Jsonrpc":"2.0","Result": ["Hello",5],"id":"9"} ]
In fact, you will find that we are providing the client with the return value of the interface, which is done according to this standard.
Accordingly, the service side of the service side of the data reception and return, but also according to this standard to do.
Change project refinement resulting from project splitting
A module corresponds to a project in which resource-oriented data access is made between projects through the rest-based interface standard.
Staffing requirements
The premise of a project split is that a project is not sufficient to meet the existing business development requirements, which means that the number of developers after the split has been amplified.
Guerrillas to the regular army to compile the leap!
Document
More projects also means more interface calls to documents, and proper processing of documents to better improve team collaboration efficiency.
Postscript
The remote invocation of the service is how to reasonably save a project that is becoming non-maintainable from the tar pits and increase the overall capacity of the project, but there is no silver bullet in the world.
Resources
- Http://www.laruence.com/2012/09/15/2779.html
- https://segmentfault.com/q/1010000000318121
- Http://wiki.geekdream.com/Specification/json-rpc_2.0.html
- Human Moon Myth
"PHP" Remote calls and RPC framework