一个非常简单的RPC服务

1.servicefunctions.php

<?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

<?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
原文地址:https://www.cnblogs.com/zuoxiaobing/p/3672372.html