Skip to content
Light, concurrent RPC framework for PHP & C (java, python etc will be supported soon)
C PHP M4 Other
Failed to load latest commit information.
packagers Refactor Yar, make the arch more clear for the persistent link Jan 8, 2013
tests use localhost Feb 26, 2015
tools fix bug Jan 6, 2014
transports Fixed issue #50 "can not get fd from curl instance" Jun 15, 2015
travis Add Travis Aug 26, 2012
.gitignore Initial commit Jun 15, 2012
.travis.yml 5.2 is not supported by travis May 1, 2016
CREDITS Fixed windows build Jun 24, 2015
EXPERIMENTAL change name to Yar , and merge some new changes Jun 19, 2012
LICENSE Fixed ISSUE #6 Add License file Jul 21, 2013 Update Oct 29, 2015
config.m4 Add build dir Sep 8, 2015
config.w32 Fix config.* Jan 2, 2014
package2.xml release yar-1.2.5 Oct 27, 2015
php_yar.h back to dev Oct 27, 2015
yar.c fixed version constant name Jan 14, 2014
yar.php change name to Yar , and merge some new changes Jun 19, 2012
yar_client.c Add Yar_Concurrent_Client::reset to meet #26 Apr 25, 2014
yar_client.h Fixed build before 5.2.6 Jan 8, 2014
yar_exception.c fix typo May 2, 2016
yar_exception.h Change DEBUG info to E_WARNING Jul 15, 2013
yar_packager.c Improve debug info Jan 10, 2013
yar_packager.h Refactor Yar, make the arch more clear for the persistent link Jan 8, 2013
yar_protocol.c Fixed header file Dec 31, 2013
yar_protocol.h More tests Jan 12, 2013
yar_request.c More tests Jan 12, 2013
yar_request.h More tests Jan 12, 2013
yar_response.c update test scripts Jan 11, 2013
yar_response.h Refactor Yar, make the arch more clear for the persistent link Jan 8, 2013
yar_server.c Attempt to fix #62 Fix the issue#61. yar_server.c:php_yar_server_hand… Oct 26, 2015
yar_server.h Refactor Yar, make the arch more clear for the persistent link Jan 8, 2013
yar_transport.c Refactor Yar, make the arch more clear for the persistent link Jan 8, 2013
yar_transport.h Fix ZTS build Jan 10, 2013
yar_transports.h Refactor Yar, make the arch more clear for the persistent link Jan 8, 2013

Yar - Yet Another RPC framework for PHP

Build Status

Light, concurrent RPC framework for PHP(c, java etc will be supported soon)


  • PHP 5.2+
  • Curl
  • Json
  • Msgpack (Optional)


Yar is a RPC framework which aims to provide a simple and easy way to do communication between PHP applications

It has the ability to concurrently call multiple remote services.


  • Fast, Easy, Simple
  • Concurrent RPC calls
  • Multiple data packager supported (php, json, msgpack built-in)
  • Multiple transfer protocols supported (http implemented, tcp/unix will be supported later)
  • Detailed debug informations


Install Yar

Yar is an PECL extension, thus you can simply install it by:

pecl install yar

Compile Yar in Linux

$./configure --with-php-config=/path/to/php-config/
$make && make install

Install Yar with msgpack

first you should install msgpack-ext

pecl install msgpack

or , you can get the github source here:


$configure --with-php-config=/path/to/php-config/ --enable-msgpack
$make && make install

Runtime Configure

  • yar.timeout //default 5000 (ms)
  • yar.connect_timeout //default 1000 (ms)
  • yar.packager //default "php", when built with --enable-msgpack then default "msgpack", it should be one of "php", "json", "msgpack"
  • yar.debug //default Off
  • yar.expose_info // default On, whether output the API info for GET requests
  • yar.content_type // default "application/octet-stream"
  • yar.allow_persistent // default Off

NOTE yar.connect_time is a value in milliseconds, and was measured in seconds in 1.2.1 and before.




It's very easy to setup a Yar HTTP RPC Server

class API {
     * the doc info will be generated automatically into service info page.
     * @params 
     * @return
    public function some_method($parameter, $option = "foo") {

    protected function client_can_not_see() {

$service = new Yar_Server(new API());

Usual RPC calls will be issued as HTTP POST requests. If a HTTP GET request is issued to the uri, the service information (commented section above) will be printed on the page:

yar service info page


It's very easy for a PHP client to call remote RPC:

Synchronous call

$client = new Yar_Client("http://host/api/");
/* the following setopt is optinal */
$client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 1000);

/* call remote service */
$result = $client->some_method("parameter");

Concurrent call

function callback($retval, $callinfo) {

function error_callback($type, $error, $callinfo) {

Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback");
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"));   // if the callback is not specificed, 
                                                                               // callback in loop will be used
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", "error_callback", array(YAR_OPT_PACKAGER => "json"));
                                                                               //this server accept json packager
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", "error_callback", array(YAR_OPT_TIMEOUT=>1));
                                                                               //custom timeout 

Yar_Concurrent_Client::loop("callback", "error_callback"); //send the requests, 
                                                           //the error_callback is optional


Yar Header

Since Yar will support multi transfer protocols, so there is a Header struct, I call it Yar Header

#ifdef PHP_WIN32
#pragma pack(push)
#pragma pack(1)
typedef struct _yar_header {
    unsigned int   id;            // transaction id
    unsigned short version;       // protocl version
    unsigned int   magic_num;     // default is: 0x80DFEC60
    unsigned int   reserved;
    unsigned char  provider[32];  // reqeust from who
    unsigned char  token[32];     // request token, used for authentication
    unsigned int   body_len;      // request body len
#ifndef PHP_WIN32
__attribute__ ((packed))
#ifdef PHP_WIN32
#pragma pack(pop)

Packager Header

Since Yar also supports multi packager protocl, so there is a char[8] at the begining of body, to identicate which packager the body is packaged by.


When a Client request a remote server, it will send a struct (in PHP):

   "i" => '', //transaction id
   "m" => '', //the method which being called
   "p" => array(), //parameters


When a server response a result, it will send a struct (in PHP):

   "i" => '',
   "s" => '', //status
   "r" => '', //return value 
   "o" => '', //output 
   "e" => '', //error or exception
Something went wrong with that request. Please try again.