(PECL yar >= 1.0.0)
Yar_Server::handle — Start the RPC server
Starts handling the incoming RPC request.
Note:
Usual RPC calls are issued as HTTP POST requests. If an HTTP GET request is issued instead, the service information page, generated from the public methods and their doc comments of the executor object, is printed. This behaviour can be disabled with the yar.expose_info directive, in which case a GET request throws a Yar_Server_Exception.
Note:
As of Yar 2.3.0, the executor object may define the protected magic methods
__infoand__authto customize the service information page and to authenticate requests; see Yar_Server::__construct() for details.
This function has no parameters.
Returns true.
| Condition | Exception |
|---|---|
| The remote method threw an exception. |
Yar_Server_Exception (with the
original class name in its _type property).
|
| The remote method was not found or is not public. | Yar_Server_Request_Exception. |
| The request body could not be unpacked. | Yar_Server_Packager_Exception. |
| The request is malformed on the protocol level. | Yar_Server_Protocol_Exception. |
| The server output could not be captured. | Yar_Server_Output_Exception. |
| Authentication failed, or the info page was requested while yar.expose_info is off. |
Yar_Server_Exception with code
YAR_ERR_FORBIDDEN.
|
Example #1 Yar_Server::handle() example
<?php
class API {
/**
* The doc block is shown on the service info page.
* @param string $parameter
* @return string
*/
public function some_method($parameter, $option = "foo") {
return "some_method";
}
protected function client_can_not_see() {
}
}
$service = new Yar_Server(new API());
$service->handle();
?>Example #2 Customizing the service information page with
__info (as of Yar 2.3.0)
<?php
class API {
public function some_method($parameter, $option = "foo") {
return "some_method";
}
/*
* Must be protected. It is called on GET requests with the markup of
* the page Yar would otherwise render, and its string return value is
* sent to the client instead.
*/
protected function __info($markup) {
return "Hello world";
}
}
$service = new Yar_Server(new API());
$service->handle();
?>