Now that we have a server, we need a client to call our methods. As mentioned before, the XML-RPC EPI extension for PHP does not make HTTP requests by itself. For that reason, before it was included in the PHP distribution, the XML-RPC EPI PHP extension came with some include files that had functions that make it a lot easier to work with XML-RPC requests. The only way to get these functions is to download the XML-RPC EPI PHP extension source package from http://xmlrpc-epi.sourceforge.net/, and install the files in the /sample/utils directory into a directory in your PHP include_path. For the purpose of the next pieces of example code, I will assume that you have copied the entire utils directory into a directory in your include_path, and renamed it xmlrpcutils.Making a client is fairly simple. The function that does all the work when we call our methods is xu_rpc_http_concise(), which is defined in the utils.php file of the xmlrpcutils directory now in our PHP include_path.First we'll make a client that calls the first method we defined in the server section of the article, the uptime method. This method does not require any parameters, so we won't pass any in. My comments about what we are doing and why will appear as comments in the code. When this is run it should print something like: The uptime on myhost.mydomain.com is 9:43pm up 5:12, 2 users, load average: 0.25, 0.24, 0.22 Where the uptime numbers are the same as those you get if you run the 'uptime' command on the server running the server script. Our second example will call the greeting method. This is one that requires a parameter - a name. When run, this should print: These are some very simple examples - xu_rpc_http_concise() can take some other arguments as well, and there are more functions available. I recommend that you read through the files in the xmlrpcutils directory to learn these for yourself.
blog comments powered by Disqus |