Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A php library for building xmlrpc clients and servers
License
gggeek/phpxmlrpc
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
XMLRPC for PHP (a.k.a. PHPXMLRPC)
A php library for building xml-rpc clients and servers.
Requirements and Installation
The recommended way to install this library is using Composer.
Detailed installation instructions are in the INSTALL.md file, along with system requirements listing.
- See the documentation page at gggeek.github.io/phpxmlrpc for a list of the library main features and all project related information, including information about online resources such as debuggers and demo servers.
- The user manual can be found in the doc/manual directory: phpxmlrpc_manual.adoc. It includes sections about upgrading from previous versions and the Backwards compatibility promise as well as about running the library’s testing suite and bundled debugger. The manual is formatted as an asciidoc file — if viewing it locally, it is recommended to either use an IDE which can natively render asciidoc, or view it as html with a browser by serving it via a webserver and accessing /doc/manual/index.html The latest version of the manual is also accessible online at https://github.com/gggeek/phpxmlrpc/blob/master/doc/manual/phpxmlrpc_manual.adoc
- Automatically-generated documentation for the API is available online at http://gggeek.github.io/phpxmlrpc/doc-4/api/index.html
- You are encouraged to look also at the code examples found in the demo/ directory. Note: to reduce the size of the download, the demo files are not part of the default package installed with Composer. You can either check them out online at https://github.com/gggeek/phpxmlrpc/tree/master/demo, download them as a separate tarball from https://github.com/gggeek/phpxmlrpc/releases or make sure they are available locally by installing the library using Composer option —prefer-install=source . Whatever the method chosen, make sure that the demo folder is not directly accessible from the internet, i.e. it is not within the webserver root directory).
- This library does include a visual debugger which can be used to troubleshoot connections to 3rd party xml-rpc servers. In case you’d like to use the debugger but do not have a working PHP installation, you can run it standalone as a Container image. Instructions can be found at https://github.com/gggeek/phpxmlrpc-debugger
- A companion PHP library, which adds support for the JSON-RPC protocol, is available at https://github.com/gggeek/phpxmlrpc-jsonrpc
- A companion PHP library, which adds support for XML-RPC servers to automatically generate API documentation, and more, is available at https://github.com/gggeek/phpxmlrpc-extras
- Lats but not least, a Javascript library, implementing both XML-RPC and JSON-RPC clients using a very similar API, is available at https://github.com/gggeek/jsxmlrpc
Use of this software is subject to the terms in the license.txt file
XML-RPC Functions
The PHP XML-RPC project at SourceForge makes life a hell of a lot easier. However, the project uses some function names which are identical to thoses provided by the XML-RPC extention.
If you are on a server with XML-RPC extension compiled in but wish to use the PHP based version then you will have to rename some of the functions.
I notice that sourceforce says there is activity on the project in 2005 but the last release was January 12, 2003.
I recommend that you use this not so friendly PHP extention if available. However this sourceforce project is still a good idea if you don’t control which extenions are be available on the server.
There’s a handy library by Keith Devens (version 2.2.1) at
http://www.keithdevens.com/software/xmlrpc/
Here is a sample client. It remotely calls sample.sumAndDifference
with two parameters (3 and 5).
It returns:
include ( «kd_xmlrpc.php» );
// define(«XMLRPC_DEBUG», 0); // Set to 1 for handy debugging
$method = «sample.sumAndDifference» ;
$params = XMLRPC_prepare (array( 3 , 5 ));
$site = «xmlrpc-c.sourceforge.net» ;
$location = «/api/sample.php» ;
list( $success , $result ) = XMLRPC_request ( $site , $location , $method , $params );
// XMLRPC_debug_print(); // uncomment for debugging
foreach ( $result as $key => $value ) <
echo( » $key => $value \n» );
>
To connect to a python xmlrpc server I use:
function do_call($host, $port, $request)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$data = curl_exec($ch);
if (curl_errno($ch)) print curl_error($ch);
> else curl_close($ch);
return $data;
>
>
$request = xmlrpc_encode_request(‘add’, array(3, 4));
$response = do_call($host, $port, $request);
for others attempting the same thing, here is what a function would look like if you wanted to send a base64 encoded file from a client and then save it onto the server. the other code necessary to call this function via an RPC is available in other comments so i won’t repeat it.
parameters:
1 — name of file
2 — base64 encoded data of file
note the use of $file_data->scalar
function sendFile($method_name, $params, $user_data) $file = «/somedir/» . $params[0];
$file_data = $params[1];
$fh = @fopen($file, «wb»);
if ($fh) if (@fwrite($fh, $file_data->scalar)) $msg = «success msg»;
> else $msg = «couldn’t write to file»;
>
fclose($fh);
return $msg;
> else return «couldn’t open file»;
>
>
?>
The documentation lacks an example that shows how to send a fault in a response. Here is how to do it:
$args = array(«faultCode» => $errcode, «faultString» => $errmsg);
$resp = xmlrpc_encode_request(NULL,$args);
//echo $resp;
If you implement an XML-RPC server with these functions and a client calls a method on your server, sending a datetime as parameter (in ISO 8601 format, as specified at http://www.xmlrpc.com/spec), the PHP XML-RPC will pass your registered server method an object as parameter. That object, for example, looks like:
obj->type=»datetime»
obj->scalar=»20040420T13:32:40″
obj->timestamp=1082460760
If you do xmlrpc_get_type(obj), it will return «datetime», so presumably that function just returns the value of ‘type’. ‘scalar’ seems to be the on-the-wire representation of the datetime (ISO 8601, exactly as received). ‘timestamp’ appears to be the ISO value in ‘scalar’ converted into a normal PHP timestamp (i.e. Unix time_t).
Note on ‘scalar’: Using a MySQL DB, we did something like «select blah where start_time >= $obj->scalar ;». That actually worked and returned expected results, so MySQL appears to handle that ISO 8601 format correctly.
Adding to what giunta dot gaetano at sea-aeroportimilano dot it and astrolox at lawyersonline dot co dot uk said about the Sourceforge PHP XML-RPC project: You can probably use function_exists() to determine whether the extension is installed so you don’t have to incur performance costs. If it’s not installed, then the function won’t exist, and function_exists() returns false. You can then fall back on the alternative library if that’s the case. For example:
if(! function_exists ( «xmlrpc_server_create» )) // include necessary files.
>
It took me a while to get a client together without external libraries. This very basic client/server pair works on my home set-up — hopefully it will save the next xml-rpc virgin some grief.
/* clienttest.php */
function do_call ( $host , $port , $request )
$fp = fsockopen ( $host , $port , $errno , $errstr );
$query = «POST /home/servertest.php HTTP/1.0\nUser_Agent: My Egg Client\nHost: » . $host . «\nContent-Type: text/xml\nContent-Length: » . strlen ( $request ). «\n\n» . $request . «\n» ;
if (! fputs ( $fp , $query , strlen ( $query ))) <
$errstr = «Write error» ;
return 0 ;
>
$contents = » ;
while (! feof ( $fp )) <
$contents .= fgets ( $fp );
>
fclose ( $fp );
return $contents ;
>
$host = ‘localhost’ ;
$port = 80 ;
$request = xmlrpc_encode_request ( ‘cycle’ , ‘egg’ );
$response = do_call ( $host , $port , $request );
/* do something with $response, e.g. print it */
?>
/* servertest.php */
function lifecycle ( $method , $params ) <
/* $method = ‘cycle’, $params = (array of) request parameter(s); $data is also passed from xmlrpc_server_call_method, if we had any data to pass */
switch( $params [ 0 ]) <
case ‘egg’ :
$reply = ‘All eggs will be birds one day.’ ;
break;
default:
$reply = ‘That must have been an otheregg’ ;
>
return $reply ;
>
/* register the ‘external’ name and then the ‘internal’ name */
xmlrpc_server_register_method ( $server , «cycle» , «lifecycle» );
$request = $HTTP_RAW_POST_DATA ; // no you don’t need ‘always on’, and no $_POST doesn’t work.
/* the parameters here are ‘server, xml-string and user data’. There’s supposed to be an optional ‘output options’ array too, but I can’t get it working 🙁 hence header() call */
$response = xmlrpc_server_call_method ( $server , $request , null );
header ( ‘Content-Type: text/xml’ );
print $response ;
If anyone is interested in making XMLRPC requests directly from the client, I have been able to get xmlrpc to
work with vcXMLRPC javascript backend.
After about 1 week of scanning the market, I found this solution to be the best on Javascript back end. It uses the Microsoft.HTTP activeX control for IE, or HTTPRequest Object for Mozilla.
You include vc(Virtual Cowboys) vcXMLRPC.js file into your pages and make the rpc calls from with javascript to create the requests.
I have tested it on IE 6.02 and you need to change lines in ProcessRequest :
function to read:
and change the getObject function to use the latest ActiveX Control:
MSXML2.XMLHTTP.3.0 (or 4.0)
MSXML2.DOMDocument.3.0 (or 4.0)
The controls are found on MSDN in the Web Services -> XML area.
As another note, you DO NOT NEED the rpcproxy.cgi script to use this. That is a proxy script to get around JS Security. You can use PHP to build the proxy. But, I was able to get the CGI working with GCC compiler on Solaris (change the -KPCI, depend and -x03 optimizer settings in the Makefile )
This XML-RPC Service makes the use XML-RPC very esay.
/**
* function myfun() returns
*@return array
*/
function myfunc () return $some_array ;
>
$ws = new XML_RPC_Server ();
$ws -> registerFunction ( ‘myfunc’ );
$ws -> run ();