Document Information

Last modified:
2011/02/22 12:31 (external edit)

This is documentation for qooxdoo 0.8.x only. You might be interested in consulting the latest docs.

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 following information is from the README.CONFIGURE file of the RpcPhp contribution.

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.php which 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.html and index.htm, but you want it also to look for index.php.

Usage

The server exists in two variants:

  1. 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.
  2. 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.

Information

Last modified:
2011/02/22 12:31 (external edit)

Account

 
 
A book on qooxdoo RIAs, authored  by community members
JS Tutorial, JavaScript Tutorial, JavaScript Guide, Learn JavaScript JS, How To Learn JS, Learning JavaScript
 

Bad Behavior has blocked 0 potential spam attempts in the last 7 days.