{"id":15524202,"url":"https://github.com/leocavalcante/rphc","last_synced_at":"2025-04-23T07:30:01.081Z","repository":{"id":72844002,"uuid":"175924797","full_name":"leocavalcante/rphc","owner":"leocavalcante","description":"PHP-to-PHP RPC Framework","archived":false,"fork":false,"pushed_at":"2019-03-16T17:18:31.000Z","size":16,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T22:41:19.099Z","etag":null,"topics":["binary-protocol","php","rpc","swoole"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leocavalcante.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-03-16T04:12:20.000Z","updated_at":"2019-09-17T03:12:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9366f63-37ad-4846-897d-a15791103fbb","html_url":"https://github.com/leocavalcante/rphc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Frphc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Frphc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Frphc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Frphc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leocavalcante","download_url":"https://codeload.github.com/leocavalcante/rphc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250390649,"owners_count":21422740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary-protocol","php","rpc","swoole"],"created_at":"2024-10-02T10:49:43.382Z","updated_at":"2025-04-23T07:30:01.053Z","avatar_url":"https://github.com/leocavalcante.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RPHC\n\nPHP-to-PHP RPC Framework.\n\n* **Async I/O** on both client and server thanks to [Swoole](https://www.swoole.co.uk/).\n    * `pecl install swoole`\n\n* **Binary protocol** on the wire thanks to [igbinary](https://github.com/igbinary/igbinary).\n    * `pecl install igbinary`\n    \n##### No HTTP overhead a.k.a raw TCP.\n\n## Usage example\n\n### Define your messages\n\n```php\nuse RPHC\\Message;\n\nclass Ekko implements Message\n{\n    private $message;\n\n    public function __construct(string $message)\n    {\n        $this-\u003emessage = $message;\n    }\n\n    public function getMessage(): string\n    {\n        return $this-\u003emessage;\n    }\n}\n\nclass Calc implements Message\n{\n    const OP_SUM = 'sum';\n    const OP_DIV = 'div';\n\n    private $op;\n    private $lt;\n    private $rt;\n\n    public function __construct(string $op, int $lt, int $rt)\n    {\n        $this-\u003eop = $op;\n        $this-\u003elt = $lt;\n        $this-\u003ert = $rt;\n    }\n\n    public function getOp(): string\n    {\n        return $this-\u003eop;\n    }\n\n    public function getLt(): int\n    {\n        return $this-\u003elt;\n    }\n\n    public function getRt(): int\n    {\n        return $this-\u003ert;\n    }\n}\n```\n\n### Write your server handlers\n\n```php\nuse RPHC\\Message;\nuse RPHC\\Result;\nuse function RPHC\\{server, success, failure};\n\nfunction ekko(Ekko $ekko): Ekko\n{\n    return new Ekko($ekko-\u003egetMessage());\n}\n\nfunction calc(Calc $calc): Result\n{\n    switch ($calc-\u003egetOp()) {\n        case Calc::OP_SUM:\n            return success($calc-\u003egetLt() + $calc-\u003egetRt());\n        break;\n\n        case Calc::OP_DIV:\n            if ($calc-\u003egetRt() == 0) {\n                return failure('Cant divide by 0');\n            }\n\n            return success($calc-\u003egetLt() / $calc-\u003egetRt());\n        break;\n    }\n\n    return failure('Noop');\n}\n\nserver('127.0.0.1', 9603)\n    -\u003ehandle(Ekko::class, 'ekko')\n    -\u003ehandle(Calc::class, 'calc')\n    -\u003estart();\n```\n\n### Write a client\n\n```php\nuse RPHC\\Result;\nuse function RPHC\\{client, send, success, failure};\n\nclient('127.0.0.1', 9603)-\u003econnect(function () {\n    send(new Ekko('Hello world'), function (Ekko $ekko) {\n        echo $ekko-\u003egetMessage().\"\\n\";\n    });\n\n    send(new Calc(Calc::OP_SUM, 42, 42), function (Result $result) {\n        echo $result-\u003eunwrap().\"\\n\";\n    });\n\n    send(new Calc(Calc::OP_DIV, 42, 0), function (Result $result) {\n        echo $result-\u003eunwrap().\"\\n\";\n    });\n});\n```\n\n### That is it!\n\n```bash\n$ php example/server.php\n```\n\n```bash\n$ php example/client.php\nHello world\n84\nCant divide by 0\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocavalcante%2Frphc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleocavalcante%2Frphc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocavalcante%2Frphc/lists"}