首页 > 其他 > 详细

一个非常简单的RPC服务

时间:2014-04-18 10:07:50      阅读:468      评论:0      收藏:0      [点我收藏+]

1.servicefunctions.php

bubuko.com,布布扣
<?php


class ServiceFunctions  {

    public    static  function getDisplayName($f,$l) {
        $name=‘‘;
        $name.=$f;
        $name.=$l;
        return $name;
    }
    public static  function countWords($c){
        return count($c);
    }
}

?>
View Code

2.index.php

bubuko.com,布布扣
<?php
require ‘servicefunctions.php‘;

if(isset($_GET[‘method‘])) {
  switch($_GET[‘method‘]) {
    case ‘countWords‘:
      $response = ServiceFunctions::countWords($_GET[‘words‘]);
      break;
    case ‘getDisplayName‘:
      $response = ServiceFunctions::getdisplayName($_GET[‘first_name‘], $_GET[‘last_name‘]);
      break;
    default:
      $response = "Unknown Method";
      break;
  }
} else {
  $response = "Unknown Method";
}

header(‘Content-Type: application/json‘);
echo json_encode($response);
?>
View Code

 

一个非常简单的RPC服务,布布扣,bubuko.com

一个非常简单的RPC服务

原文:http://www.cnblogs.com/zuoxiaobing/p/3672372.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!