国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial AMFPHP php遠程調(diào)用(RPC, Remote Procedure Call)工具 快速入門_PHP

AMFPHP php遠程調(diào)用(RPC, Remote Procedure Call)工具 快速入門_PHP

Jun 01, 2016 pm 12:18 PM
Quick start

它可以使PHP與下述技術(shù)無縫通信:
(1) Flash 和 Flex Remoting
(2) JavaScript JSON 和 Ajax JSON
(3) XML 和XML-RPC
什么是RPC
遠端程序調(diào)用(RPC, Remote Procedure Call) 是一種客戶端與服務(wù)器端交換數(shù)據(jù)方式。我們可以調(diào)用本地對象帶對各種參數(shù)方法設(shè)置回調(diào)并接受調(diào)用結(jié)果。我們不用關(guān)心發(fā)送和接收數(shù)據(jù)的實現(xiàn)細節(jié)。實現(xiàn)細節(jié)通常是抽象的,就像我們在調(diào)用本地方法一樣。
AMFPHP的工作原理
 客戶端(Flash / Flex)與服務(wù)器端(PHP) 使用相同的方式描述方法調(diào)用和復(fù)雜數(shù)據(jù)。客戶端序列化請求并將它發(fā)送到網(wǎng)關(guān)AMFPHP。AMFPHP再執(zhí)行:
  (1) 反序列化請求
  (2) 找到相應(yīng)的遠程服務(wù)類
  (3) 實例化類
  (4) 執(zhí)行安全檢查
  (5)(使用指定參數(shù))調(diào)用服務(wù)器端方法
  (6) 序列化返回的數(shù)據(jù)
  AMFPHP可以正確地序列化、反序列化復(fù)雜類型數(shù)據(jù)。除了對象和數(shù)組,它還支持 resources 數(shù)據(jù)連接資源,這就意味著我們可以通過調(diào)用遠程方法簡單返回mysql_query,amfphp 會處理這一切。如果平臺支持 (目前來說,F(xiàn)lash Remoting 和Flex Remoting),AMFPHP還可以處理循環(huán)引用和自定義數(shù)據(jù)它也支持簡單的遠程調(diào)試。還有AMFPHP附帶一個瀏覽器,它可以在創(chuàng)建客戶端代碼前測試遠程服務(wù)。AMFPHP 1.0.1還添加了模板,可以自動生成客戶端代碼。AMFPHP 1.9 beta更是新增了對AMF3的支持。
簡單示例
下面我們通過一個簡單的登錄示例來對AMFPHP有一個初步的認識,將分別從客戶端和服務(wù)器端兩個部分進行介紹。
一,F(xiàn)lex客戶端:
代碼
復(fù)制代碼 代碼如下:
import mx.controls.Alert;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.rpc.events.*;
public var login_remoteObj:RemoteObject = null;
public function initLoginRemoteObject():void
{//初始化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
{//登陸操作,向服務(wù)器提交數(shù)據(jù)
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
{//處理服務(wù)器返回的結(jié)果
var result:Array = event.result as Array;
var flag:String = result[0];
if (flag == "0") {
Alert.show("登陸失敗: " + result[1]);
} else if (flag == "1") {
Alert.show("登陸成功: " + result[1]);
} else if (flag == "-1") {
Alert.show("異常: " + result[1]);
}
}
public function faultHandler(event: FaultEvent):void
{//出錯處理
Alert.show("sorry,出錯了!!!");
}
}

二,PHP服務(wù)器端
1,將amfphp文件夾置于MyTest項目的根目錄下,打開瀏覽器輸入下述地址驗證amfphp是否安裝成功
復(fù)制代碼 代碼如下:
http://localhost/MyTest/amfphp/gateway.php

amfphp就是通過這個gateway來定位我們的服務(wù)類,并將請求轉(zhuǎn)發(fā)給這些服務(wù)類進行處理的。
2,Login.php文件,包含了處理登陸請求的Login類,此文件置于BusinessLogic目錄下
代碼
復(fù)制代碼 代碼如下:
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,將globals.php中的服務(wù)路徑項修改如下,為amfphp指明服務(wù)類所在的目錄
復(fù)制代碼 代碼如下:
$servicesPath = "../BusinessLogic/";

作者:洞庭散人
AMFPHP 下載地址
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Python learning: How to install the pandas library in the system Python learning: How to install the pandas library in the system Jan 09, 2024 pm 04:42 PM

Quick Start: How to install the pandas library in Python requires specific code examples 1. Overview Python is a widely used programming language with a powerful development ecosystem that includes many practical libraries. Pandas is one of the most popular data analysis libraries. It provides efficient data structures and data analysis tools, making data processing and analysis easier. This article will introduce how to install the pandas library in Python and provide corresponding code examples. 2. Install Py

Quick Start with the Mojs Animation Library: A Guide to the Explosion Module Quick Start with the Mojs Animation Library: A Guide to the Explosion Module Sep 02, 2023 pm 11:49 PM

We start this series by learning how to animate HTML elements using mojs. In this second tutorial, we continue using the Shape module to animate built-in SVG shapes. The third tutorial covers more ways to animate SVG shapes using ShapeSwirl and the stagger module. Now we will learn how to animate different SVG shapes in bursts using the Burst module. This tutorial will depend on the concepts we introduced in the previous three tutorials. If you haven't read them yet, I recommend reading them first. Creating a Basic Burst Animation The first thing we need to do before creating any burst animation is to instantiate a Burst object. Afterwards, we can specify different properties

Quick Start: Use Go language functions to implement a simple audio streaming service Quick Start: Use Go language functions to implement a simple audio streaming service Jul 29, 2023 pm 11:45 PM

Quick Start: Implementing a Simple Audio Streaming Service Using Go Language Functions Introduction: Audio streaming services are becoming more and more popular in today's digital world, which allow us to play audio files directly over the network without performing a complete download. This article will introduce how to use Go language functions to quickly implement a simple audio streaming service so that you can better understand and use this function. Step 1: Preparation First, you need to install the Go language development environment. You can download it from the official website (https://golan

Quick Start: Use Go language functions to implement simple image recognition functions Quick Start: Use Go language functions to implement simple image recognition functions Jul 30, 2023 pm 09:49 PM

Quick Start: Use Go language functions to implement simple image recognition functions In today's technological development, image recognition technology has become a hot topic. As a fast and efficient programming language, Go language has the ability to implement image recognition functions. This article will provide readers with a quick start guide by using Go language functions to implement simple image recognition functions. First, we need to install the Go language development environment. You can download the appropriate version on the Go language official website (https://golang.org/)

Learn a quick start using five Kafka visualization tools Learn a quick start using five Kafka visualization tools Jan 31, 2024 pm 04:32 PM

Quick Start: A Guide to Using Five Kafka Visualization Tools 1. Kafka Monitoring Tools: Introduction Apache Kafka is a distributed publish-subscribe messaging system that can handle large amounts of data and provide high throughput and low latency. Due to the complexity of Kafka, visualization tools are needed to help monitor and manage Kafka clusters. 2.Kafka visualization tools: five major choices KafkaManager: KafkaManager is an open source web community

Quick Start: Use Go language functions to implement a simple video streaming service Quick Start: Use Go language functions to implement a simple video streaming service Aug 01, 2023 pm 02:29 PM

Quick Start: Implementing a Simple Video Streaming Service Using Go Language Functions Introduction: Video streaming services play an important role in modern applications. This article will introduce how to use Go language functions to implement a simple video streaming service. We will use the net/http package of Go language to handle HTTP requests, and combine it with the FFmpeg library to handle the encoding and decoding of video streams. Step 1: Install FFmpeg Before we start writing code, we need to install the FFmpeg library. Can be accessed through FFmpeg official website

Quick Start: Use Go language functions to implement simple data aggregation functions Quick Start: Use Go language functions to implement simple data aggregation functions Jul 29, 2023 pm 02:06 PM

Quick Start: Use Go language functions to implement simple data aggregation functions. In software development, we often encounter situations where we need to aggregate a set of data. Aggregation operations can count, summarize, calculate, etc., to analyze and display data. In the Go language, we can use functions to implement simple data aggregation functions. First, we need to define a data type to represent the data we want to aggregate. Suppose we have a student's grade table, and each student has two fields: name and grade, then we can create the following structure

Recommend five commonly used frameworks in Go language to help you get started quickly Recommend five commonly used frameworks in Go language to help you get started quickly Feb 24, 2024 pm 05:09 PM

Title: Get Started Quickly: Recommended Five Common Go Language Frameworks In recent years, with the popularity of the Go language, more and more developers have chosen to use Go for project development. The Go language has received widespread attention for its efficiency, simplicity and superior performance. In Go language development, choosing a suitable framework can improve development efficiency and code quality. This article will introduce five commonly used frameworks in the Go language, and attach code examples to help readers get started quickly. Gin framework Gin is a lightweight web framework that is fast and efficient.

See all articles