Table of Contents
PHP RPC
qooxdoo includes an advanced RPC mechanism for direct calls to server-side methods. It allows you to write true client/server applications without having to worry about the communication details.
As described in the RPC overview, qooxdoo RPC is based on JSON-RPC as the serialization and method call protocol. This page describes how to set up and implement a PHP-based server.
Setup
The simplest configuration of the PHP JSON-RPC server requires these steps:
- Copy the services directory to the root of your web server's data directory, e.g.
/var/www
- Ensure that PHP is properly configured. Try placing a file in the services directory called
test.phpwhich contains this data:
<?php
phpinfo();
?>
You should then be able to access http://your.domain.com/services/test.php and see the phpinfo() output. If not, you have a web server / php configuration problem to work out.
- Configure your web server to load index.php if it's found in a directory specified by the URL. By default, the web server probably looks only for
index.htmlandindex.htm, but you want it also to look forindex.php.
Usage
The server exists in two variants:
- Version 1.0.X is a drop-in / all-in-one script that works with PHP 5.1 and 5.2 and is very lightweight and easy to include in your application.
- Starting with ver. 1.1.X, the server has been rewritten in an object-oriented and extensible way. Ver. 1.1.X supports PHP 4.3-5.3., later versions will only support PHP 5 and up.
How it works: It receives a service name in dot-separated path format and expect to find the class containing the service in a file of the service name (with dots converted to slashes and ".php" appended). If the service name is "foo.bar.Baz", the class can be named "class_Baz" or "class_foo_bar_Baz". The name of the service method is prefixed by "method_", so "doFoo" becomes "method_doFoo()".
Use of versions >= 1.1.0:
require "path/to/services/server/JsonRpcServer.php"; $server = new JsonRpcServer; $server->start();
You can also use the index.php provided in this package.
The service classes are placed in the "class/" subfolder. You can also choose a different location for the service classes by defining the "servicePathPrefix" in the global_settings.php file (if you use it) or elsewhere in your code. Make sure to include a trailing slash. Multiple service paths are also supported (to be documented).
The server is extremely flexible, you can subclass the JsonRpcServer and finetune almost every aspect of its behavior by overriding the different methods. Also, the class uses the behavior design pattern by delegation of accessibility and error behaviors to separate objects.
As an example for the subclassing of the server, a PostRpcServer class has been included which can be used for testing purposes. This class transforms GET and POST requests into jsonrpc requests. This can serve as an example how to write other servers on top of the jsonrpc server (for example, using XML-RPC, etc.).
Debugging and testing
Use the RpcExample contribution to make sure your PHP backend works as expected. In order to debug your custom service classes, use the RpcConsole contribution.
