PHPackages                             so-php/rpc - 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. so-php/rpc

ActiveLibrary[API Development](/categories/api)

so-php/rpc
==========

RPC pattern via php-amqplib

0.0.2-alpha(11y ago)1212PHP

Since Jun 14Pushed 11y ago1 watchersCompare

[ Source](https://github.com/so-php/rpc)[ Packagist](https://packagist.org/packages/so-php/rpc)[ RSS](/packages/so-php-rpc/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (2)

rpc
===

[](#rpc)

RPC Pattern via php-amqplib

Avoiding Technology Lockout
---------------------------

[](#avoiding-technology-lockout)

One of the goals of ths implementation is to prevent locking out other technologies like python, ruby and java from producing or consuming requests. This is not a terribly difficult task--it just means we need to use a non-proprietary message queue (php-amqplib + rabbitmq) and a message format that isn't language specific. Hence we choose to use a json serialized data structure rather than a PHP serialized string.

That being said, there are no enforced restrictions on the content of the PRC params. It is up to developers to keep vigilant and be sure not to stuff anything in an RPC that is PHP or platform specific.

Message Structure
-----------------

[](#message-structure)

As stated above, the message is a plain Json string. The structure is an object with three keys (only) at the top level.

- `method` the method name
- `params` an array to hold rpc params. No imposed limits other than technical feasibility and reasonableness. Params should be present even if empty `[]`. Params are ordered, and will be provided to the RP in the same order they are received.

```
{
    "name": "sayHelloTo",
    "params": [
        "bob"
    ]
}

```

Usage
-----

[](#usage)

Using RPC is pretty straight forward. Words in uppercase are values that need to be supplied/configured.

### Server

[](#server)

First we need to start an RPC Server queue and bind it a class/method.

```
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();

$server = new Server($ch);
$server->serve(function($name){ return "Hello $name"; }, 'greet');
// or more commonly:
// $rpc->serve(new Greeter()); // where greeter has a greet method.

echo "listening for RPCs @ " . $server->getQueueName();
while(true){
    $server->wait();
}

```

Output might look something like:

```
`Listening for RPCs @ amq.gen-v1ac3`

```

### Client

[](#client)

The client looks a bit like this:

```
// need a channel to work with
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();

// we have to tell the client what queue to use
$rpc = new Client($ch, 'amq.gen-v1ac3');

$greeting = $rpc->greet('bob');
echo $greeting;

```

Output might look like:

```
`Hello bob`

```

#### Wait, wait, wait...

[](#wait-wait-wait)

"You mean I have to somehow orchestrate configuring my RPC client with the correct queue for the server?" I hear you asking. The answer is, unapologetically, yes. But *you* shouldn't do that, you should use a service registry pattern for that. Try [so-php/service-registry](https://github.com/so-php/service-registry).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

2

Last Release

4354d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2445eabf60869a0410b641fbec7b87fea798e5d12e6e31120223cbc230a97ec?d=identicon)[jeremygiberson](/maintainers/jeremygiberson)

---

Top Contributors

[![jeremygiberson](https://avatars.githubusercontent.com/u/487411?v=4)](https://github.com/jeremygiberson "jeremygiberson (2 commits)")

### Embed Badge

![Health badge](/badges/so-php-rpc/health.svg)

```
[![Health](https://phpackages.com/badges/so-php-rpc/health.svg)](https://phpackages.com/packages/so-php-rpc)
```

PHPackages © 2026

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