Skip to content

Instantly share code, notes, and snippets.

@pokisin
Created December 4, 2018 16:39
Show Gist options
  • Save pokisin/e03e3ab25c72c3ecca29a66fa74e7b43 to your computer and use it in GitHub Desktop.
Save pokisin/e03e3ab25c72c3ecca29a66fa74e7b43 to your computer and use it in GitHub Desktop.
RPC Framework
<?php
// Service for basic operations from server
class Operacion {
/**
* Add two operands
* @param interge
* @return interge
*/
public function add($a, $b) {
return $this->_add($a, $b);
}
/**
* subtraction
*/
public function sub($a, $b) {
return $a - $b;
}
/**
* multiplication
*/
public function mul($a, $b) {
return $a * $b;
}
/**
* Protected methods will not be exposed
* @param interge
* @return interge
*/
protected function _add($a, $b) {
return $a + $b;
}
}
$server = new Yar_Server(new Operacion());
$server->handle();
?>
//_______________How to consume the service on the client's side________________
<?php
$client = new Yar_Client("http://localhost/yarw/index.php");
$result = $client->add(20,10);
echo $result.'<hr>';
echo $client->mult(10, 20);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment