Remove typechecker-only options from GlobalOptions to avoid code duplication
[hiphop-php.git] / hphp / doc / server.rpc_server
blob4bdccaea752b69e31f405b26d5d7c6785911812f
2 <h2> How to execute a PHP function over network</h2>
4 1. Parameters
6 When RPC server is turned on, HipHop server will listen on a port that takes
7 RPC requests in a format like this,
9   http://[server]:[port]/function_name?params=...
11 "params" needs to be a JSON encoded array. The server will execute the function
12 and return its result.
14 Alternatively, one can pass in one parameter a time like this,
16   http://[server]:[port]/function_name?p=[json value]&p=[json value]...
18 Each "p" is sequentially fed into the function as its first parameter, second
19 parameter, etc.. Each parameter needs to be encoded in JSON separately.
21 There is also an "auth" parameter that needs to be passed in, if server is
22 configured to authenticate with a simple password. It would normally be a
23 password specified in /hphp/config.hdf under Satellites.rpc.Password.
25 2. States
27 Note that RPC server is considerably faster than an ajax page request, because
28 it has made an assumption that the function needed to run this way is "pure" or
29 "stateless", without leaving bad global states to subsequent calls. With this
30 assumption, the server only initializes libraries once and it will execution
31 multiple function calls (the number is configurable) within the same loop.
32 This is very similar to FastCGI's paradigm.
34 If you need to call a function that leaves bad states to other functions,
35 please add "reset=1" to the parameter, so the states can be thrown away after
36 the function is called:
38   http://[server]:[port]/function_name?reset=1&...
40 3. Returns
42 If stdout is needed in addition to function's return, use "output=2", and
43 HTTP response is a JSON encoded array like this,
45   array {
46     "return" => [function's return]
47     "output" => [stdout from echos or prints]
48   }
50 If function's return is not needed, use "output=1" to turn it off. Then HTTP
51 response is stdout's output (from echos and prints) without JSON encoding.
53 If none is needed, use "output=-1" to suppress them. Then an empty string will
54 be returned. This may be useful, if the function is not a query but an action.
56 If more complete information about the return value is needed, use "output=3"
57 to obtain a PHP-serialized string.
59 By default, "output=0" and function's return is encoded in JSON response.
61 To summarize,
63 0: (default) just function's return in JSON encoding
64 1: just stdout as a string without JSON encoding
65 2: both function's return and stdout in a JSON encoded array
66 3: just function's return with PHP serialization
67 -1: none
69 4. File invocation
71 RPC server now supports direct invocation of a PHP file, under the same
72 assumption that the request is stateless.
74 There are two cases. First, the purpose of the RPC call is still to invoke a
75 function, but the definition of the function is in a file that is not in the
76 normal initialization path, defined by the RequestInitDocument. In order to
77 invoke the function reliably, you can add "include=..." or "include_once=..."
78 to the request:
80   http://[server]:[port]/function_name?include_once=file_name.php&...
82 The difference between include and include_once here is just like that in
83 normal PHP scripts. A file that is included once on an RPC request will only
84 execute once for the entire life time of an RPC request handler.
86 The second case is that you can directly invoke a file, without calling a
87 function:
89   http://[server]:[port]/?include=file_name.php&...
91 or just
93   http://[server]:[port]/file_name.php?...
95 In this case, you would probably want to use "output=1" for the file
96 invocation, as a file does not return a value. You would also want to
97 use "include=...", rather than "include_once=...".