Getting Started with WebORB for PHP

WebORB for PHP provides a Flex Remoting, Data Management and Flex Messaging implementation. Using WebORB, PHP developers can integrate Flash, Flex, Silverlight and AJAX client applications with objects deployed in PHP applications.

This guide provides an overview of creating a Flex client using Flex Builder and connecting it with a PHP application. The result of the walkthrough is a Flex application communicating with a PHP object exposed through WebORB for PHP.

WebORB for PHP installation has the following directory structure:

┬  WEBORB Installation directory

├── index.php
------- management console point of entry

├── weborb.php
------- main PHP script - place it into the 
│                      same directory where your compiled SWF
are located and adjust paths in the
require_once calls in the file

├── /Services
------- contains deployed 'remotable' PHP classes

├── /examples
------- contains examples shipped with WebORB

├── /Console 
------- contains WebORB Management Console
│     │     
│     ├─ index.php 
----- main console page
│     │     
│     └─ weborb.php 
----- remoting entry point for the console

├── /weborbassets
│     │     
│     └─ weborb.swc 
----- client-side class library,
│                          required for messaging apps

└── /Weborb  
------- contains configuration, log and
     │               WebORB for PHP source code
     ├─ weborb-config.xml 
----- contains a reference to the
     │                           /Services folder, as well as other
important weborb configuration 
     └─ /WEB-INF
         └─ /flex
           ├─ remoting-config.xml
 -- configures Flex destinations
           ├─ messaging-config.xml
 -- configures Flex messaging
           └─ services-config.xml 
-- configures Flex RPC endpoint

If you are deploying on a Windows computer with IIS, make sure to grant Read/Write permissions to the IUSR_<machinename> account for the /Weborb folder.

You can verify the installation by running WebORB Management Console included with the WebORB distribution.  Open localhost/[WEBORB INSTALL PATH]/index.php in a browser. When the console is loaded, you can inspect available PHP remoting services using the Management tab or run the examples included with the product.

Flex Builder Setup

To create a Flex Builder project to work with WebORB for PHP, follow the instructions from this article or watch this screencast.

Flex Application Code

WebORB for PHP product distribution contains a finished Flex application demonstrating Flex to WebORB connectivity and a remoting invocation. Copy and paste the contents of the example.mxml file located at


into the mxml file created in Flex Builder. The code in the application connects to a PHP object and retrieves some basic information about the computer where the object is running.

In order to communicate with a remote PHP object, Flex application uses the RemoteObject API to create a remoting proxy:
remoteObject = new RemoteObject();
remoteObject.destination = "InfoServiceDestination";
remoteObject.addEventListener("fault", onFault);

Notice the destination name matches the destination entered in remoting-config.xml. When a user clicks the 'Get Computer Info' button, the following function executes a remote method invocation:
private function getInfo():void
  invokeButton.enabled = false;
  currentUserText.text = "";
  processIdText.text = "";
  osText.text = "";
  phpVersionText.text = "";

When an invocation response is available, Flex invokes a response handler specified in the <RemoteObject> tag. The response handler in the example, populates the text fields with the data available in the returned object:
private function onResult(event:ResultEvent):void
  var computerInfo:Object = event.result;
  currentUserText.text = computerInfo.currentUser;
  processIdText.text = computerInfo.phpProcessId;
  osText.text = computerInfo.operatingSystem;
  phpVersionText.text = computerInfo.phpVersion;
  invokeButton.enabled = true;

PHP Code

The source code for the server-side PHP class is below:
class InfoService
  public function getComputerInfo()
    $compInfo = new ComputerInfo();
    $compInfo->currentUser = get_current_user();
    $compInfo->phpProcessId = getmypid();
    $compInfo->operatingSystem = php_uname( 'a' );
    $compInfo->phpVersion = phpversion();
    return $compInfo;

class ComputerInfo
  public $currentUser;
  public $phpProcessId;
  public $operatingSystem;
  public $phpVersion;


IMPORTANT: Make sure to locate the directory where Flex Builder copies the compiled client application. It is very important to place a copy of weborb.php into the same directory.
weborb.php must contain the following PHP code:


   $m_ORBHttpHandler = new ORBHttpHandler();

VERY IMPORTANT: The first line must be edited to point to the Weborb directory from the product distribution. For example, look at weborb.php located in the /Console folder

Run Flex Application

At this point the Flex client is ready to run. You can use Flex Builder to launch the application.