Giter Site home page Giter Site logo

swoole-jsonrpc's Introduction

swoole-JsonRPC

use swoole for jsonRpc(运用swoole简单实现jsonRPC)

Requirements

  • PHP 5.3+
  • Swoole 1.7.16
  • Linux, OS X and basic Windows support (Thinks to cygwin)

Installation Swoole

  1. Install from pecl

    pecl install swoole
    
  2. Install from source

    sudo apt-get install php5-dev
    git clone https://github.com/swoole/swoole-src.git
    cd swoole-src
    phpize
    ./configure
    make && make install
    

使用

  • 下载swoole-JsonRPC
  • 解压swoole-JsonRPC并进入目录
  • 服务端执行命令php index.php
  • 客户端例子见client/client.php
    <?php
      include 'RpcClient.php';
    	//配置服务端列表
    	$address_array = array(
    		'127.0.0.1:6666',
    		'127.0.0.1:6666'
    	);
    	RpcClient::config($address_array);
    	
    	//检测是否装了swoole扩展有则用swoole_client方式,没有则用socket方式
    	if (extension_loaded('swoole')) {
    		RpcClient::setSwooleClient();
    	}
    	
    	// User对应/Jsonrpc/Services/User.php 中的User类
    	$user_client = RpcClient::instance('User');
    	// getInfoByUid对应User类中的getInfoByUid方法
    	$uid = 567;
    	$ret_sync = $user_client->getInfoByUid($uid);
    	var_dump($ret_sync);
    	//通过rpc操作redis的例子
    	$redis_client = RpcClient::instance('MyRedis');
    	$set_res = $redis_client->set('jsonrpc','hello json rpc654', 30);
    	var_dump($set_res);
    	$get_res = $redis_client->get('jsonrpc');
    	var_dump($get_res);
    	//调用不存在的函数
    	$list_res = $redis_client->list('jsonrpc');
    	var_dump($list_res);
    

swoole-jsonrpc's People

Contributors

toxmc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.