PHP code example of kodhe / xmlrpc

1. Go to this page and download the library: Download kodhe/xmlrpc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kodhe / xmlrpc example snippets




declare(strict_types=1);

use Kodhe\Framework\Xmlrpc\Xmlrpc;

$rpc = new Xmlrpc();

$rpc->server('https://example.com/xmlrpc.php', 443);
$rpc->method('wp.getPostFormats');
$rpc->request([
    ['postId' => 1, 'username' => 'admin', 'password' => 'rahasia'],
]);

if ($rpc->send_request() !== false) {
    print_r($rpc->display_response());   // array hasil dekode
} else {
    echo $rpc->display_error();          // fault string
}

$rpc->request([
    $rpc->xmlrpc_int,      // <int>
    $rpc->xmlrpc_boolean,  // <boolean>
    $rpc->xmlrpc_string,   // <string>
    $rpc->xmlrpc_base64,   // <base64>
    $rpc->xmlrpc_struct,   // <struct> (assoc array)
    $rpc->xmlrpc_array,    // <array>  (list array)
    $rpc->xmlrpc_datetime, // <dateTime.iso8601>
]);

$rpc->server('http://rpc.example.com/xmlrpc.php', 80,
            'proxy.example.com', 8080);  // lewat proxy
$rpc->timeout(15);                        // detik
$rpc->set_debug(true);                    // log request/response

use Kodhe\Framework\Xmlrpc\Client\XmlRpcClient;

$client = new XmlRpcClient();           // factory memilih transport/encoder default
$client->setServer('https://example.com/xmlrpc.php', 443)
       ->setTimeout(10)
       ->setDebug(false);

$result = $client->call('system.listMethods');     // array | false
if ($result === false) {
    echo $client->getLastError();
}

$rpc->send_error_message(404, 'Method tidak ditemukan'); // panggil fault XML
$rpc->send_response(['ok' => true]);                     // panggil success XML

$fault = $rpc->display_error();  // string pesan fault dari server

src/
├── Xmlrpc.php               # Kelas utama kompatibel CI3
├── Client/XmlRpcClient.php  # Klien OO modern (setServer/call)
├── Message/                 # XmlRpcMessage (request), XmlRpcResponse
├── Encoder/ Decoder/        # encode/decode payload XML-RPC
├── Transport/ + Factory/    # HTTP transport (curl/stream)
├── ValueObjects/XmlRpcValue.php
├── Contracts/ Support/ Exceptions/