Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Xmlrpc Client Laravel Package

ang3/php-xmlrpc-client

Lightweight PHP XML-RPC client inspired by Ripcord. Create a client with the server URL and call remote methods with optional args. Requires the php-xmlrpc extension. Throws transport and remote exceptions for failed requests or server errors.

View on GitHub
Deep Wiki
Context7
## Getting Started

### Minimal Setup
1. **Installation**
   ```bash
   composer require ang3/php-xmlrpc-client

Add the namespace to your composer.json autoload or use:

use Ang3\XmlRpc\Client;
  1. First Request

    $client = new Client('http://example.com/RPC2');
    $response = $client->call('methodName', ['param1', 'param2']);
    print_r($response);
    
  2. Key Files to Review

    • src/Client.php (Core client logic)
    • src/Request.php (Request building)
    • src/Response.php (Response handling)

First Use Case: WordPress API

$client = new Client('https://yoursite.com/xmlrpc.php');
$response = $client->call('wp.getUsersBlogs', ['username']);

Implementation Patterns

Workflow: Structured API Calls

  1. Instantiate Client

    $client = new Client('https://api.example.com/xmlrpc', [
        'timeout' => 10,
        'user_agent' => 'MyApp/1.0'
    ]);
    
  2. Batch Requests

    $client->call('method1', [$arg1]);
    $client->call('method2', [$arg2]);
    $client->send(); // Send all queued requests
    
  3. Error Handling

    try {
        $response = $client->call('methodName', [$arg]);
    } catch (\Ang3\XmlRpc\Exception\FaultException $e) {
        // Handle XML-RPC fault
        log::error($e->getMessage());
    } catch (\Exception $e) {
        // Handle other errors
    }
    

Integration Tips

  • Laravel Service Provider

    public function register()
    {
        $this->app->singleton('xmlrpc', function ($app) {
            return new Client(config('xmlrpc.endpoint'));
        });
    }
    
  • Queueable Jobs

    use Illuminate\Bus\Queueable;
    
    class XmlRpcJob implements ShouldQueue
    {
        use Queueable;
    
        public function handle()
        {
            $client = app('xmlrpc');
            $client->call('processData', [$this->data]);
        }
    }
    
  • Caching Responses

    $cacheKey = 'xmlrpc_method_' . md5(serialize($args));
    $response = Cache::remember($cacheKey, 3600, function () use ($client, $method, $args) {
        return $client->call($method, $args);
    });
    

Gotchas and Tips

Pitfalls

  1. Fault Handling

    • XML-RPC faults throw FaultException with a faultCode and faultString.
    • Always wrap calls in try-catch blocks.
  2. Data Type Mismatches

    • Ensure PHP types match XML-RPC types (e.g., boolean vs int).
    • Use is_bool(), is_int(), etc., for validation.
  3. Timeouts

    • Default timeout is 0 (infinite). Set explicitly:
      $client = new Client('url', ['timeout' => 5]);
      
  4. Base64 Encoding

    • Binary data must be base64-encoded before sending:
      $binaryData = base64_encode(file_get_contents('file.pdf'));
      $client->call('upload', [$binaryData]);
      

Debugging

  • Enable Debugging

    $client = new Client('url', ['debug' => true]);
    

    Logs requests/responses to storage/logs/xmlrpc.log.

  • Inspect Raw Requests

    $request = $client->getRequest();
    file_put_contents('debug.xml', $request->getXml());
    

Extension Points

  1. Custom Request/Response Classes Extend \Ang3\XmlRpc\Request or \Ang3\XmlRpc\Response for custom logic.

  2. Middleware Implement \Ang3\XmlRpc\Middleware\MiddlewareInterface for request/response filtering.

  3. Transport Layer Override the HTTP client by implementing \Ang3\XmlRpc\Transport\TransportInterface.

Configuration Quirks

  • Default Headers The client adds Content-Type: text/xml and User-Agent automatically. Override via:

    $client = new Client('url', ['headers' => ['X-Custom' => 'Value']]);
    
  • SSL Verification Disable with:

    $client = new Client('url', ['verify_ssl' => false]);
    

    (Use cautiously in production.)

  • PHP 8.0 Compatibility

    • The package now supports PHP 8.0 features like named arguments and union types.
    • Ensure your Laravel application is using PHP 8.0+ to leverage these improvements.
    • If using PHP 8.0+, you can utilize type-safe method calls:
      $response = $client->call('methodName', ['param1' => 'value1', 'param2' => 123]);
      

Performance Tips

  • Reuse Client Instances Instantiate once and reuse for multiple calls to avoid connection overhead.

  • Compress Large Payloads Enable gzip compression for large requests:

    $client = new Client('url', ['compression' => true]);
    

NO_UPDATE_NEEDED would not apply here as the PHP 8.0 compatibility addition warrants updating the **Configuration Quirks** section.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor