浏览模式: 标准 | 列表
constructor PHPRPC_Client();
constructor PHPRPC_Client(string serverURL);
constructor PHPRPC_Client(string serverURL, array functions);
constructor PHPRPC_Client.create();
constructor PHPRPC_Client.create(string serverURL);
constructor PHPRPC_Client.create(string serverURL, array functions);

Create PHPRPC Client object. The username and password can be contained in serverURL for HTTP Basic Authorization, but it is NOT recommended (see also useService method for the recommended usage). To use create method create PHPRPC Client object in VBScript.

If you hope that the PHPRPC Client initialize remote functions without connecting to the PHPRPC Server, you can use the parameter functions.

useService(string serverURL);
useService(string serverURL, string username, string password);
useService(string serverURL, string username, string password, array functions);

Set the URL of the PHPRPC Server. The username and password can be contained in serverURL for HTTP Basic Authorization, but it is NOT recommended. It is recommended to specify the username and password by parameters.

If you hope that the PHPRPC Client initialize remote functions without connecting to the PHPRPC Server, you can use the parameter functions.

boolean setKeyLength(int keyLength);

Set the key length for the key exchange. This method will return false when the key exchange already to be done.

int getKeyLength();

Get the key length. This method will return actual value when the key exchange being done. Otherwise, you will get the default length or which length you set.

boolean setEncryptMode(int encryptMode);

Set the encrypt mode. 0 denotes no encrypting any data. 1 denotes encrypting arguments in the transfer. 2 denotes encrypting arguments and result. 3 denotes encrypting arguments, result and output of the server console. Set other value, it would return false.

int getEncryptMode();

Get the encrypt mode.

string remoteFunctionName(arg1, arg2, ..., argN);
string remoteFunctionName(arg1, arg2, ..., argN, callbackFunction);
string remoteFunctionName(arg1, arg2, ..., argN, callbackFunction, byRef);

Invoke the server function directly. The return value is remoteFunctionID, you can use abort method to abort the remoteFunction with this value. You can specify a callbackFunction, when the remote function completed, this callbackFunction will be call automatically. If you want to transfer the arguments by reference, set byRef to be true. If you didn’t specify a callbackFunction, the default callback function is remoteFunctionName_callback(), You can define it separately. the callbackFunction can be defined like this:

callbackFunction = function (result, args, output, warning) {
   ...
}

The parameter result is the remote function result, when an error occurred during invoking remote function, this parameter is a PHPRPC_Error object. The parameter args is the remote function arguments, you can get the changed arguments with it when transfering the arguments by reference. The parameter output is the output of the server console after invoke the remote function. The parameter warning is the warning of the server function after invoke the remote function, it is a PHPRPC_Error object.

onready();

This is a event. When the useService method completes, this event will be fired.

boolean getReady();

When the useService method completes, this method return true, otherwise return false.

string invoke(remoteFunctionName, arg1, arg2, ..., argN);
string invoke(remoteFunctionName, arg1, arg2, ..., argN, callbackFunction);
string invoke(remoteFunctionName, arg1, arg2, ..., argN, callbackFunction, byRef);

This method is similar to remoteFunctionName in calling remote function. The difference is the invoke method is available before the ready property becomes true, that is to say, this method can be called immediately after using useService method.

abort();
abort(string remoteFunctionID);

If you used this method without parameter, it would stop all of the remote functions. If you specified the remoteFunctionID, it would only stop the remote function you specified.

setTimeout(int timeout);

Set the timeout of the invoking of the remote function. the timeout is the number of milliseconds. Default value is 30 seconds. If you want to disable timeout, set timeout to 0 or null.

int getTimeout();

Get the timeout of the invoking the remote function. the return value is the number of milliseconds.

constructor PHPRPC_Error(int errno, string errstr);

You never need to create PHPRPC_Error object by yourself, when an error occurred during invoking remote function, this object will be created automatically as the result of callback function.

int getNumber();

return error number.

string getMessage();

return error message.

string toString();

return a string which include the error number and error message.

» 阅读全文

7月
08

PHPRPC 3.0 for PHP API Draft

Server API:

constructor PHPRPC_Server();

Create the PHPRPC Server object.

add(string funcname);
add(string funcname, null, string alias);
add(string[] funcnames);
add(string[] funcnames, null, string[] aliases);
 
add(string funcname, object obj);
add(string funcname, object obj, string alias);
add(string[] funcnames, object obj);
add(string[] funcnames, object obj, string[] aliases);
 
add(string funcname, string classname);
add(string funcname, string classname, string alias);
add(string[] funcnames, string classname);
add(string[] funcnames, string classname, string[] aliases);

Add global functions, instance methods or static methods to the server. The functions or the methods can have aliases. This method must be called before start().

add(object obj);

Add all methods from obj to the server. This method must be called before start().

setCharset(string charset);

Set the charset of the server. This method must be called before start();

setDebugMode(boolean debug);

Set the debug mode of the server. This method must be called before start();

start();

Start the PHPRPC server. This method usually be called at the end of page. This method can NOT be called twice or more in one page.

Client API:

constructor PHPRPC_Client();
constructor PHPRPC_Client(string serverURL);

Create PHPRPC Client object. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend.

setProxy(string address);
setProxy(string host, string port);
setProxy(string host, string port, string username, string password);

Set the proxy server for the transfer. The address supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You can set the address to NULL to cancel the proxy server.

useService(string serverURL);
useService(string serverURL, string username, string password);

Set the URL of the PHPRPC Server. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You’d better to set username and password alone.

boolean setKeyLength(integer keyLength);

Set the key length for the key exchange. This method will return false when the key exchange already to be done.

integer getKeyLength();

Get the key length. This method will return actual value when the key exchange being done. Otherwise, you will get the default length or which length you set.

boolean setEncryptMode(integer encryptMode);

Set the encrypt mode. 0 denotes no encrypting any data. 1 denotes encrypting arguments in the transfer. 2 denotes encrypting arguments and result. 3 denotes encrypting arguments, result and output of the server console. Set other value, it would return false.

integer getEncryptMode();

Get the encrypt mode.

setCharset(string charset);

Set the request charset. Use it before invoke the remote function. The default value is “UTF-8″ or as the response charset.

string getCharset();

Get the response charset. Use it after invoke the remote function.

setTimeout(int timeout);

Set the timeout of the invoking of the remote function. the timeout is the number of seconds. Default value is 30 seconds.

integer getTimeout();

Get the timeout of the invoking the remote function. the return value is the number of seconds.

invoke(string funcname, object[] args);
invoke(string funcname, object[] args, boolean byRef);

Invoke the server function with the function name and arguments array. if you want to transfer the arguments by reference, set byRef to be true.

remoteFunctionName(arg1, arg2, ..., argN);

Invoke the server function directly. You can’t transfer the arguments by reference in this mode.

string getOutput();

Get the output of the server console after invoke the server function.

PHPRPC_Error getWarning();

Get the warning of the server function after invoke the server function.

constructor PHPRPC_Error(int errno, string errstr);

You never need to create PHPRPC_Error object by yourself, when an error occurred during invoking remote function, this object will be created automatically as the result of remote function.

integer getNumber();

return error number.

string getMessage();

return error message.

string toString();

return a string which include the error number and error message.

» 阅读全文

Server API:

constructor PHPRPC_Server();

Create the PHPRPC Server object.

boolean add(String funcname, Object obj);
boolean add(String funcname, Object obj, String alias);
boolean add(String[] funcnames, Object obj);
boolean add(String[] funcnames, Object obj, String[] aliases);
 
boolean add(String funcname, Class cls);
boolean add(String funcname, Class cls, String alias);
boolean add(String[] funcnames, Class cls);
boolean add(String[] funcnames, Class cls, String[] aliases);

Add instance methods or static methods to the server. The methods can have aliases. This method must be called before start().

boolean add(Object obj);

Add all instance methods from obj to the server. This method must be called before start().

boolean add(Class cls);

Add all static methods from cls to the server. This method must be called before start().

void setCharset(String charset);

Set the charset of the server. This method must be called before start();

void setDebugMode(boolean debug);

Set the debug mode of the server. This method must be called before start();

void setEnableGZIP(boolean enableGZIP);

Set enable GZIP of the server. This method must be called before start();

void start(HttpServletRequest request, HttpServletResponse response);

Start the PHPRPC server. This method usually be called at the end of page. This method can NOT be called twice or more in one page.

Client API:

constructor PHPRPC_Client();
constructor PHPRPC_Client(String serverURL);

Create PHPRPC Client object. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend.

void setProxy(String address) throws MalformedURLException;
void setProxy(String host, int port);
void setProxy(String host, int port, String username, String password);

Set the proxy server for the transfer. The address supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You can set the address to null to cancel the proxy server.

boolean useService(String serverURL);
boolean useService(String serverURL, String username, String password);

Set the URL of the PHPRPC Server. The serverURL supports using username and password for the HTTP Basic Authorization, but it is NOT recommend. You’d better to set username and password alone.

Object useService(Class type);
Object useService(Class[] interfaces);

Get a service proxy object instance. The type Class is a interface or a class implements a group of interfaces. The interfaces is a group of interfaces which the service proxy object instance implements.

Object useService(String serverURL, Class type);
Object useService(String serverURL, Class[] interfaces);
Object useService(String serverURL, String username, String password, Class type);
Object useService(String serverURL, String username, String password, Class[] interfaces);

Set the URL of the PHPRPC Server and get a service proxy object instance.

boolean setKeyLength(int keyLength);

Set the key length for the key exchange. This method will return false when the key exchange already to be done.

int getKeyLength();

Get the key length. This method will return actual value when the key exchange being done. Otherwise, you will get the default length or which length you set.

boolean setEncryptMode(int encryptMode);

Set the encrypt mode. 0 denotes no encrypting any data. 1 denotes encrypting arguments in the transfer. 2 denotes encrypting arguments and result. 3 denotes encrypting arguments, result and output of the server console. Set other value, it would return false.

int getEncryptMode();

Get the encrypt mode.

void setCharset(String charset);

Set the request charset. Use it before invoke the remote function. The default value is “UTF-8″ or as the response charset.

String getCharset();

Get the response charset. Use it after invoke the remote function.

void setTimeout(int timeout);

Set the timeout of the invoking of the remote function. the timeout is the number of milliseconds. Default value is 30 seconds.

int getTimeout();

Get the timeout of the invoking the remote function. the return value is the number of milliseconds.

Object invoke(String funcname, Object[] args);
Object invoke(String funcname, Object[] args, boolean byRef);

Invoke the server function with the function name and arguments array. if you want to transfer the arguments by reference, set byRef to be true.

String getOutput();

Get the output of the server console after invoke the server function.

PHPRPC_Error getWarning();

Get the warning of the server function after invoke the server function.

constructor PHPRPC_Error(int errno, String errstr);

You never need to create PHPRPC_Error object by yourself, when an error occurred during invoking remote function, this object will be created automatically as the result of remote function.

int getNumber();

return error number.

String getMessage();

return error message.

String toString();

return a string which include the error number and error message.

» 阅读全文

因为 PHPRPC 的 QQ 群已经接近满员,最近关注 PHPRPC 的用户也越来越多,因此,在 PHPRPC 网站上专门开了一个技术交流论坛,欢迎大家参与讨论!地址是:http://www.phprpc.org/forum

以后,关于 PHPRPC 最新信息的发布,会在论坛里第一时间出现,而 CoolCode.CN 将只作为 PHPRPC 的公共信息的发布点,而更多更全更详细的信息将只在论坛发布。

» 阅读全文

在 PHPRPC 3.0 for javascript 客户端中,关于跨域调用的使用,跟非跨域调用没有区别。只要在客户端中使用跨域服务器的绝对地址就可以了。例如上一节中的例子,如果其中客户端初始化语句改为:

var rpc = new PHPRPC_Client('http://www.phprpc.org/samples/sha1.php', ['sha1']);

,并且客户端网页与该网站不在同一个域中的话,那么它就会自动转为跨域调用模式。而服务器端不需要做任何特殊设置。

但跨域调用在 PHPRPC 中是如何实现的呢?

» 阅读全文