It enables PHP to communicate seamlessly with the following technologies:
(1) Flash and Flex Remoting
(2) JavaScript JSON and Ajax JSON
(3) XML and XML-RPC
What is RPC
Remote Program invocation (RPC, remote Procedure call) is a way for clients to exchange data with the server side. We can call the local object with the various parameter methods to set the callback and accept the call result. We don't care about the implementation details of sending and receiving data. Implementation details are often abstract, just as we call local methods.
How the amfphp works
The client (Flash/flex) describes method invocations and complex data in the same way as the server side (PHP). The client serializes the request and sends it to the Gateway amfphp. amfphp re-execution:
(1) Deserialization request
(2) Find the appropriate remote service class
(3) Instantiation class
(4) Performing security checks
(5) Invoking the server-side method (using the specified parameters)
(6) Serialization of returned data
Amfphp can serialize and deserialize complex types of data correctly. In addition to objects and arrays, it also supports resource data connection resources, which means that we can simply return mysql_query,amfphp by invoking a remote method to handle all this. If the platform supports (for now, Flash Remoting and Flex Remoting), amfphp can also handle circular references and custom data and it also supports simple remote debugging. And amfphp comes with a browser that can test the remote service before creating the client code. AMFPHP 1.0.1 also adds a template that can generate client code automatically. AMFPHP 1.9 Beta has added support for AMF3.
Simple example
Below, we have a preliminary understanding of amfphp with a simple login example, which will be described in two sections from the client and server side respectively.
One, Flex client:
Code
Copy CodeThe code is as follows:
Import Mx.controls.Alert;
Import Mx.rpc.remoting.mxml.RemoteObject;
Import mx.rpc.events.*;
public var login_remoteobj:remoteobject = null;
Public Function Initloginremoteobject (): void
{//Initialize RemoteObject
This.login_remoteobj = new RemoteObject ();
This.login_remoteObj.source = "Login";
This.login_remoteObj.destination = "amfphp";
This.login_remoteObj.showBusyCursor = true;
This.login_remoteObj.endpoint = "http://localhost/MyTest/amfphp/gateway.php";
This.login_remoteObj.doLogin.addEventListener ("result", Loginhandler);
This.login_remoteObj.doLogin.addEventListener ("Fault", Faulthandler);
}
Public Function Dologin (): void
{//login operation, submit data to server
var name:string = This.txtName.text;
var pwd:string = This.txtPassword.text;
var data:array = new Array ();
Data.push (name);
Data.push (PWD);
This.login_remoteObj.getOperation ("Dologin"). Send (data);
}
Public Function Loginhandler (event:resultevent): void
{//processing the results returned by the server
var Result:array = Event.result as Array;
var flag:string = result[0];
if (flag = = "0") {
Alert.show ("Login failed:" + result[1]);
} else if (flag = = "1") {
Alert.show ("Landing success:" + result[1]);
} else if (flag = = "-1") {
Alert.show ("Exception:" + result[1]);
}
}
Public Function Faulthandler (event:faultevent): void
{//Error handling
Alert.show ("Sorry, error!!!");
}
}
Two, PHP server-side
1, place the amfphp folder in the root directory of the MyTest project, open the browser and enter the address below to verify that the amfphp is successful.
Copy CodeThe code is as follows:
http://localhost/MyTest/amfphp/gateway.php
Amfphp is using this gateway to locate our service classes and forward requests to those service classes for processing.
The 2,login.php file contains the login class that handles the login request, which is placed in the Businesslogic directory
Code
Copy CodeThe code is as follows:
Class Login
{
Public Function Dologin ($data)
{
$result = Array ();
try {
$name = Array_shift ($data);
$pwd = Array_shift ($data);
if ($name = = "Phinecos" && $pwd = = "123") {
$result [] = "1";
$result [] = "You are valid user!";
} else {
$result [] = "0";
$result [] = "Login Failed";
}
} catch (Exception $ex) {
$result [] = "1";
$result [] = $ex->getmessage ();
}
return $result;
}
}
?>
3, modify the service path entry in globals.php as follows, specifying the directory where the service class is located for amfphp
Copy CodeThe code is as follows:
$servicesPath = ". /businesslogic/";
Author: Cave Court scattered people
AMFPHP Download Address
http://www.bkjia.com/PHPjc/321785.html www.bkjia.com true http://www.bkjia.com/PHPjc/321785.html techarticle It enables PHP to communicate seamlessly with the following technologies: (1) Flash and Flex Remoting (2) JavaScript JSON and Ajax JSON (3) XML and xml-rpc What is RPC remote program call (RPC, remote Procedure ...