CodyKochmann
4/14/2017 - 7:36 PM

make xmlrpc requests to a xmlrpc server in native php (and not subshells)

make xmlrpc requests to a xmlrpc server in native php (and not subshells)

<?
#========================================================================================
# this function makes a xmlrpc request to a server
# author: Cody Kochmann
# example usage:
#   echo xmlrpc_request('http://localhost:8000/server.php','say_hello',array('marcin'));
#========================================================================================
function xmlrpc_request($server_url, $service_name, $request_args){
        $response = xmlrpc_decode(
        file_get_contents(
            $server_url,
            false,
            stream_context_create(
                array(
                    'http' => array(
                    'method' => "POST",
                    'header' => "Content-Type: text/xml\nUser-Agent: PHPRPC/1.0\n",
                    'content' => xmlrpc_encode_request(
                        $service_name,
                        $request_args
                    )
                    )
                )
            )
        )
    );
    return (xmlrpc_is_fault($response) ? 'xmlrpc: '.$response['faultString'].' ('.$response['faultCode'].')' : $response);
}