PHPackages                             bit3/remote-objects - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. bit3/remote-objects

AbandonedArchivedLibrary[API Development](/categories/api)

bit3/remote-objects
===================

Remote object method invokation framework

1.2.1(12y ago)776[1 issues](https://github.com/bit3archive/php-remote-objects/issues)1MITPHP

Since Jan 24Pushed 12y ago1 watchersCompare

[ Source](https://github.com/bit3archive/php-remote-objects)[ Packagist](https://packagist.org/packages/bit3/remote-objects)[ Docs](https://github.com/bit3/php-RemoteObjects)[ RSS](/packages/bit3-remote-objects/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (1)

Remote object method invocation framework
=========================================

[](#remote-object-method-invocation-framework)

[![Build Status](https://camo.githubusercontent.com/29d812da98c46fbe42b6c8d5559fc758256f06d66821bd569b360c7800c9a9ab/68747470733a2f2f7472617669732d63692e6f72672f626974332f7068702d72656d6f74652d6f626a656374732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/bit3/php-remote-objects) [![API DOCS](https://camo.githubusercontent.com/f6bfb01c5fdd2d6fcb18b73a285c89e48dd084ffba49631da474b78fe205e307/68747470733a2f2f626974332e64652f66696c65732f49636f6e732f617069646f63732e706e67)](http://bit3.github.io/php-remote-objects/)

Com'on, not another method invocation framework? Aren't there enough XML-RPC, JSON-RPC and similar implementations out there? Yes, there are, but they are not flexible enough and most of them do not provide any security features like encryption.

The benefit of RemoteObjects is to provide a remote method invocation framework, that is secure (allow encryption), flexible (allow different transports like unix socket) and interoperable (support JSON-RPC 2.0 by default, but can also support XML-RPC or other protocols). Every component is exchangeable, if you like, you are also able to invoke a method via SMS as transport layer, or just use your own protocol instead of JSON-RPC. Everything is possible!

Or in other words: This framework combines the pros of all the others ;-)

How it works
------------

[](#how-it-works)

```
user -> Client::invoke($method, $params)
         \
          \--> Encoder::encodeMethod($method, $params)
                     /
        $request   Transport\Client::request($request)
                |
                |
       HTTP or something else :-)
                |
                V
              Transport\Server::receive()
                     /
        $request   Encoder::decodeMethod($request)
                               /
        [$method, $params]   Server::invokeArgs($method, $params)
                \
                 \--> $target->$method($params..)
                            /
               $result   Encoder::encodeResult($result)
                             /
               $response  Transport\Server:respond($response)
                       |
                       |
                All the way back
                       |
                       V
                      Transport\Client::request(...)
                      /
        $response  Encoder::decodeResult($response)
                    /
        $result handle();
```

`client.php`

```
$transport = new RemoteObjects\Transport\UnixSocketClient('/tmp/socket.client', '/tmp/socket.server');

$encoder = new RemoteObjects\Encode\JsonRpc20Encoder();

$server = new RemoteObjects\Client(
	$transport,
	$encoder
);
$result = $server->invoke('reply', 'Tristan');
echo $result; // -> "Hello Tristan"
```

Chaining and deep structure
---------------------------

[](#chaining-and-deep-structure)

Inspired from another JSON-RPC library, RemoteObjects allow complex structures on the server side. Sometimes you need a complex remote api, but you won't to overload your remote object class. Instead of creating multiple endpoints, it's possible to create multiple "named" remote objects.

Creating named objects is realy easy:

```
$server = new RemoteObjects\Server(
	$transport,
	$encoder,
	array(
		'a' => $targetA,
		'b' => $targetB
	)
);
```

To call methods from `$targetA` or `$targetB` you just have to prefix the method name with the object name, concatenated with a dot.

```
$client->invoke('a.methodA'); // invoke $targetA->methodA();
$client->invoke('b.methodB'); // invoke $targetB->methodB();
```

It is also possible to make bigger, more complex and multidimensional structures.

```
$server = new RemoteObjects\Server(
	$transport,
	$encoder,
	array(
		'a' => array(
			'one' => $targetOne,
			'two' => array(
				'I' => $targetI,
				'II' => $targetII
			)
		),
		'b' => $targetB
	)
);
```

To call `$targetII->method()` for example, the method name will be `a.two.II.method`.

Hint: You can also use `ArrayAccess` compatible objects, instead of arrays!

For better and more programmatic chaining, is is possible to access the structure by virtual attributes of the `RemoteObject` objects. Accessing a property of `RemoteObject` will give you a new `RemoteObject` instance to this named path (similar to `Client::getRemoteObject()`).

According to the previous example, access to `a.two.II.method` is also possible this way:

```
$result = $client
	->castAsRemoteObject()
	->a
	->two
	->II
	->method();
```

Lazy objects
------------

[](#lazy-objects)

In the last chapter, you read about chaining and deep structures. But if your API grows up, creating all target objects may waste a lot of resources. Instead of using arrays or `ArrayAccess` objects, you can make a class with getters for the named objects.

```
class Objects
{
	public function getA()
	{
		return new TargetA();
	}

	public function getB()
	{
		return new TargetB();
	}
}
```

And then use this object as target.

```
$server = new RemoteObjects\Server(
	$transport,
	$encoder,
	new Objects()
);
```

To access methods from `TargetA` or `TargetB` it is the same as before, use `a.methodName` to invoke `TargetA::methodName` or `b.methodName` to invoke `TargetB::methodName`.

Remote object accessors
-----------------------

[](#remote-object-accessors)

RemoteObjects allow to create `RemoteObject` objects to directly call the methods on it.

On the server side:

```
$server = new RemoteObjects\Server(
	$transport,
	$encoder,
	array(
		'a' => $targetA,
		'b' => $targetB
	)
);
```

On the client side:

```
$remoteA = $client->getRemoteObject('a');
$remoteB = $client->getRemoteObject('b');
```

Now `$remoteA` is an accessor to `$targetA` and `$remoteB` to `$targetB`. Keep in mind that `$remoteA` and `$remoteB` are just proxies without any methods. Every method is dynamically passed to the server side.

If you don't have named objects on the server side, you can also pack the complete client object as `RemoteObject`.

```
$remote = $client->castAsRemoteObject();
```

Now every call `$remote->method($arg1, $arg2, ...)` will directly passed to `$client->invokeArgs('method', [$arg1, $arg2, ...])`.

Type mapping
------------

[](#type-mapping)

One big problem of remote method invocation, and the previous shown method is the nescience of the remote methods. Every object you get with `Client::getRemoteObject` or `Client::castAsRemoteObject` is just a primitive proxy, without any methods. You are unable to use `method_exists` or `ReflectionClass` to "inspect" the object and its methods.

To solve this problem, RemoteObjects allow you to specify a type, to use as `RemoteObject`. Just specify your type, when calling `Client::getRemoteObject` or `Client::castAsRemoteObject`.

```
interface MyRemote
{
	public function remoteMethod();
}

$remote = $client->castAsRemoteObject('MyRemote');
```

Since version 1.2 you can also use a class.

```
class MyRemote
{
	public function remoteMethod()
	{
		// ...
	}
}

$remote = $client->castAsRemoteObject('MyRemote');
```

The object `$remote` **is** an instance of `MyRemote`, but it is also an instance of `RemoteObjects\RemoteObject`.

How this works? Internally a virtual temporary proxy class is generated, named `RemoteProxies\__WS__\MyRemote` (the namespace is prefixed, in previous version the class name was suffixed) that implements the interface.

With this technique you can make nearly every object remote and pass the object to other methods without type hint mismatch. All you need is an interface.

Known limitations
-----------------

[](#known-limitations)

- Pass parameters by reference is impossible for remote objects.
- Parameters that are unable to be serialized cannot be transported to the remote endpoint.

Security
--------

[](#security)

Sometimes you want to increase security, but your transport layer does not support encryption (for example you cannot use HTTPS for some reason). RemoteObjects provides an `AesEncoder` and a `RsaEncoder` that encrypt the data before transport and decode before evaluation.

Using the `AesEncoder` or `RsaEncoder`, is really simple.

### AES

[](#aes)

Server and client:

```
$jsonEncoder = new RemoteObjects\Encode\JsonRpc20Encoder();
$encoder = new RemoteObjects\Encode\AesEncoder(
	$jsonEncoder,
	''
);
```

### RSA

[](#rsa)

Server:

```
$jsonEncoder = new RemoteObjects\Encode\JsonRpc20Encoder();
$encoder = new RemoteObjects\Encode\RsaEncoder(
	$jsonEncoder,
	'',
	''
);
```

Client:

```
$jsonEncoder = new RemoteObjects\Encode\JsonRpc20Encoder();
$encoder = new RemoteObjects\Encode\RsaEncoder(
	$jsonEncoder,
	'',
	''
);
```

Logging
-------

[](#logging)

Monolog is supported, but not required. You can add a logger to each transport, encoder or server/client object to log errors and debug informations.

```
$logger = new \Monolog\Logger('RemoteObjects');
$logger->pushHandler(new StreamHandler('php://stderr', Logger::ERROR));

$transport->setLogger($logger);

$encoder->setLogger($logger);

$server->setLogger($logger);
// or
$client->setLogger($logger);
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 97.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Total

4

Last Release

4674d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e61f74ea186c1e79e072b2974ccdeef39414730476d5a8adac501eb9449b2a3?d=identicon)[tril](/maintainers/tril)

---

Top Contributors

[![tristanlins](https://avatars.githubusercontent.com/u/343404?v=4)](https://github.com/tristanlins "tristanlins (34 commits)")[![xat](https://avatars.githubusercontent.com/u/182512?v=4)](https://github.com/xat "xat (1 commits)")

---

Tags

jsonapiencryptionrsaaesrpcremotejson-rpcxml-rpcmethod

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bit3-remote-objects/health.svg)

```
[![Health](https://phpackages.com/badges/bit3-remote-objects/health.svg)](https://phpackages.com/packages/bit3-remote-objects)
```

###  Alternatives

[tivoka/tivoka

The universal JSON-RPC client/server library. JSON-RPC done right!

74159.0k3](/packages/tivoka-tivoka)[jsonrpc/jsonrpc

JSON-RPC 2.0 client/server implementation

53407.1k4](/packages/jsonrpc-jsonrpc)[tbondois/odoo-ripcord

Ripoo : a PHP8 XML-RPC client handler for Odoo External API

16124.3k1](/packages/tbondois-odoo-ripcord)[ufo-tech/rpc-exceptions

Exception package RPC server error codes

164.2k4](/packages/ufo-tech-rpc-exceptions)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
