The PHPRPC uses an instance (which is true but cannot perform) function conflicts Gzdecode

Source: Internet
Author: User
Tags mul php server

PHPRPC is a lightweight, secure, cross-network, cross-lingual, cross-platform, cross-domain, cross-field, multi-tiered, support-enabled, service-oriented, high-performance remote procedure call protocol that supports the transfer of reference parameters, supports content output redirection, supports hierarchical error handling, and supports session.

Summary of issues encountered:

Fatal error:cannot redeclare gzdecode () in
1. Rename compat.php, phprpc_client.php gzdecode (and system function conflicts) function as Gzdecode_other

Non-static method Phprpc_server::initsession () should not be called statically
2, modify the phprpc_server.php file inside the Initsession function type is static.

3, phprpc_client.php 472 line Warning:
notice:undefined offset in phprpc_client.php line 472
Modified into
$arr = explode (' = ', $c, 2);
if (count ($arr) >1)
{
List ($name, $value) = $arr;
if (!in_array ($name, Array (' domain ', ' expires ', ' path ', ' secure '))) {
$_phprpc_cookies[$name] = $value;
}
}
4. Warning:the Magic Method __get () must has public visibility and cannot is static in compat.php (235): eval () ' D code on Line 3
Change to public:
Eval ('
Class '. $classname. ‘ {
Public Function __get ($name) {

PHP Server Side

<?phpinclude (' php/phprpc_server.php '); include ' entitys.php '; function Hello ($name) {    return ' hello '. $name;} $server = new Phprpc_server (); $server->setcharset (' UTF-8 '); $server->setdebugmode (true); $server Setenablegzip (true); $server->add (' hello '); $server->add (' sort ');//$server->add (Array (' Hello ', ' md5 ', ' SHA1 '), $server->add (' getcwd ');//export PHP built-in function $server->add (' Add ', New Calculator ()); $server->add (' Mul ', new Calculator ()); $server->add (' div ', New Calculator ()), $server->add (' Sub ', New Calculator ()); $server->add (' Fuck ', new Calculator ()), $server->add (' getstudent ', New Calculator ()), $server->add (' getstudents ', new Calculator ()); $server->start ();? >

<?phpclass student{public $id;    Public $name; public $age;}     /** * Calculator-sample class to expose via Json-rpc */class calculator{/** * Return sum of both variables * * @param int $x * @param int $y * @return int */Public function Add ($x, $y) {return $x + $y    ;    }/** * Return difference of variables * * @param int $x * @param int $y * @return int */    Public Function sub ($x, $y) {return $x-$y; }/** * Return product of variables * * @param int $x * @param int $y * @return int */P    ublic function Mul ($x, $y) {return $x * $y;     }/** * Return The division of the variables * * @param int $x * @param int $y * @return Float    */Public Function div ($x, $y) {return $x/$y;        Public Function Fuck ($STR, $x, $y) {$m = $x + $y; Return ' Fuck Japan '. $str.    $m; } Public Function getStudent ($student) {$student = new student ();        $student->id = 110;        $student->name = ' php ';        $student->age = 21;    return $student;        Public Function getstudents ($id) {$entitys = array ();            for ($i =0; $i <10; $i + +) {$student = new student ();            $student->id = $i;            $student->name = ' English php '. $i;            $student->age = 21;        Array_push ($entitys, $student);    } return $entitys; }}?>

  

PHP Client Clients

<?phpinclude ("php/phprpc_client.php"); $client = new Phprpc_client (' http://localhost/phprpc/index.php '); Echo ' <br/> '; $ret = $client->add (12,32);p rint_r ($ret); Echo ' <br/> '; $ret = $client->mul (12,32);p Rint_r ($ (ret); Echo ' <br/> '; $ret = $client->fuck (' xx test ', 12,32);p Rint_r ($ret); Echo ' <br/> '; $ret = $client Hello (' xx test ', 12,32);p Rint_r ($ret); Echo ' <br/> '; $ret = $client->getstudent (' getstudent ');p rint_r ($ret); Echo ' <br/> '; $ret = $client->getstudents (' getstudents ');p rint_r ($ret); Echo ' <br/> ';p rint_r ($client- >getoutput ());? >

  

Java Client:

Package Com.jiepu.client;import Org.phprpc.phprpc_client;import Org.phprpc.util.assocarray;import Org.phprpc.util.cast;public class Incclient {//Http://leyteris.iteye.com/blog/1004669//http://www.phprpc.org/zh_ Cn/docs///android below also public static void main (string[] args) {phprpc_client Client = new Phprpc_client ("HTTP/ 10.0.0.108/phprpc/index.php "); System.out.println (Client.invoke ("Add", new object[] {12, 32}); System.out.println (Client.invoke ("Sub", new object[] {12, 32}); System.out.println (Client.invoke ("Mul", new object[] {12, 32}); System.out.println (Client.invoke ("div", new object[] {12, 32}); System.out.println (Cast.tostring (Client.invoke ("Fuck", new object[] {"Hehe hello", 12, 32})); System.out.println (Cast.tostring (Client.invoke ("GETCWD", new object[] {})); System.out.println (Cast.tostring (Client.invoke ("Hello", new object[] {"Java"}));//public public class student Auto-mapping convert Object Obj=client.invoke ("Getstudent", new object[] {"Java"}); Student stu= (Student) cast.cast (obj, Student.claSS); System.out.println (stu);/** manual Conversion hashmap<object, object> Objs = (hashmap<object, object>) Client.invoke (" Getstudent ", new object[] {" Java "}), if (Objs.size () >0) {Student Student = new Student (); Student.setage ( Integer.parseint (Cast.tostring (Objs.get ("Age"))); Student.setname (cast.tostring ("name")); Student.setid (Integer.parseint (cast.tostring (Objs.get ("id"))); SYSTEM.OUT.PRINTLN (student); System.out.println ("===========");} */assocarray alist = (assocarray) client.invoke ("Getstudents", new object[] {"Java"}); for (int i = 0; i < alist.size () ; ++i) {//System.out.println (Alist.get (i). GetClass ()); Student student= (Student) cast.cast (Alist.get (i), student.class); SYSTEM.OUT.PRINTLN (student);} System.out.println (Client.getwarning ());}}

  

Package Com.jiepu.client;import Java.io.serializable;public class Student implements Serializable {private static final Long serialversionuid = 3475272786622279878l;private integer id;private String name;private integer age; @Overridepublic String toString () {return "Student [age=" + Age + ", id=" + ID + ", name=" + name+ "]";} Public Integer GetId () {return ID;} public void SetId (Integer id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public Integer Getage () {return age;} public void Setage (Integer age) {this.age = age;}}

  

Android Client:

Package Com.example.androidjsonrpc;import Java.util.list;import Org.alexd.jsonrpc.jsonrpcclient;import Org.alexd.jsonrpc.jsonrpcexception;import Org.alexd.jsonrpc.jsonrpcparams.versions;import org.phprpc.PHPRPC_ Client;import Org.phprpc.util.assocarray;import Org.phprpc.util.cast;import Android.app.activity;import Android.os.bundle;import Android.util.log;import Android.view.view;import Com.alibaba.fastjson.json;public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main);} public void run (view view) {New Thread (new Runnable () {@Overridepublic void run () {runinthread ()}). Start ();} public void Runphprpc (view view) {New Thread (new Runnable () {@Overridepublic void run () {RUNPHPRPC ()}}). Start ();} private void Runphprpc () {phprpc_client Client = new Phprpc_client ("http://10.0.0.108/phprpc/index.php"); System.out.println (Client.invoke ("Add", new object[] {12, 32}); System.out. println (Client.invoke ("Sub", new object[] {12, 32}); System.out.println (Client.invoke ("Mul", new object[] {12, 32}); System.out.println (Client.invoke ("div", new object[] {12, 32}); System.out.println (Cast.tostring (Client.invoke ("Fuck", new object[] {"Hehe hello", 12, 32})); System.out.println (Cast.tostring (Client.invoke ("GETCWD", new object[] {})); System.out.println (Cast.tostring (Client.invoke ("Hello", new object[] {"Java"}));//public public class student Auto-mapping convert Object Obj=client.invoke ("Getstudent", new object[] {"Java"}); Student stu= (Student) cast.cast (obj, student.class); System.out.println (stu);/** manual Conversion hashmap<object, object> Objs = (hashmap<object, object>) Client.invoke (" Getstudent ", new object[] {" Java "}), if (Objs.size () >0) {Student Student = new Student (); Student.setage ( Integer.parseint (Cast.tostring (Objs.get ("Age"))); Student.setname (cast.tostring ("name")); Student.setid (Integer.parseint (cast.tostring (Objs.get ("id"))); SYSTEM.OUT.PRINTLN (student); System.out.priNtln ("===========");} */assocarray alist = (assocarray) client.invoke ("Getstudents", new object[] {"Java"}); for (int i = 0; i < alist.size () ; ++i) {//System.out.println (Alist.get (i). GetClass ()); Student student= (Student) cast.cast (Alist.get (i), student.class); SYSTEM.OUT.PRINTLN (student);}} public void Runinthread () {//https://code.google.com/p/android-json-rpc/downloads/list//http://www.oschina.net/p/ Android-json-rpcjsonrpcclient client = jsonrpcclient.create ("http://10.0.0.107/json_server/server.php", versions.version_2); Client.setconnectiontimeout (+); Client.setsotimeout (+); try {string string = Client.callstring ("Fuck", "android Google", 15, 32); LOG.I ("Androidjsonrpc", "fuck=" + string); int i = Client.callint ("Add", 56, 25); LOG.I ("Androidjsonrpc", I + "");//Student student= (Student) client.call ("Getstudent", new//Student (1, "name", 123));// LOG.I ("Androidjsonrpc", student.tostring ());//LOG.I ("Androidjsonrpc", Client.call ("Getstudent", new//student (1, " Name ", 123)). ToString ());//LOG.I ("Androidjsonrpc", Client.call ("getstudents",//"XX"). toString ()); String str = client.callstring ("Getstudent", New Student (1, "name", 123)); LOG.I ("Androidjsonrpc", str);//Fastjson convert JSON string to object student student = Json.parseobject (str, student.class); LOG.I ("Androidjsonrpc", student.tostring ()); str = client.callstring ("getstudents", "xx"); LOG.I ("Androidjsonrpc", str);//Use to Fastjson convert the JSON array to the list object list<student> students = Json.parsearray (str, Student.class); LOG.I ("Androidjsonrpc", students.tostring ());} catch (Jsonrpcexception e) {e.printstacktrace ();}}}

  

Delphi Client:

Unit unit4;interfaceuses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Phprpcsynah    Ttpclient, Phprpc, Phprpcclient, phprpcidhttpclient, Stdctrls;type TFORM4 = Class (Tform) Button1:tbutton;    Phprpcidhttpclient1:tphprpcidhttpclient;    Phprpcsynahttpclient1:tphprpcsynahttpclient;  Procedure Button1Click (Sender:tobject);  Private {Private declarations} public {public declarations} end;    Tstudent = Class (Tphpobject) private fid:integer;    fname:ansistring;  Fage:integer;    Published property Id:integer read FID write FID;    Property name:ansistring read Fname write Fname;  Property Age:integer read Fage write Fage; End;var form4:tform4;implementation{$R *.dfm}procedure tform4.button1click (sender:tobject); var clientproxy:variant  ;  Int_ret, I:integer;  string_ret:string;  Vhashmap:variant;  Ohashmap:thashmap;  ArrayList, Keys, values:tarraylist;  Key, value, tmp:variant; Student:tstudent;begin// Http://www.phprpc.org/zh_CN/docs/clientProxy: = Phprpcidhttpclient1.useservice (' http://10.0.0.108/phprpc/  Index.php ');  Int_ret: = Clientproxy.add (12, 52);  ShowMessage (IntToStr (Int_ret));  Chinese string parameter to be converted to UTF8 encoding String_ret: = Clientproxy.fuck (' xxx hello '), 15, 45);  The Chinese server output is also UTF8 encoded, local printing to be converted to local encoding showmessage (Utf8toansi (String_ret));  String_ret: = CLIENTPROXY.GETCWD ();  ShowMessage (Utf8toansi (String_ret));  String_ret: = Clientproxy.hello (AnsiToUTF8 (' xxx '));  ShowMessage (Utf8toansi (String_ret));  Tstudent.registerclass (' Student ');  TMP: = Clientproxy.getstudent (AnsiToUTF8 (' Java '));  ShowMessage (Utf8toansi (TMP));  Convert to student object student: = Tstudent (Tstudent.fromvariant (TMP));  ShowMessage (IntToStr (student.id) + ', ' + utf8toansi (student.name) + ', ' + inttostr (student.age));  Vhashmap: = clientproxy.getstudents (AnsiToUTF8 (' Java '));  Ohashmap: = Thashmap (Thashmap.fromvariant (Vhashmap)); ArrayList: = Ohashmap.  Toarraylist; For I: = 0 to ArrayList. Count-1 do beGin//ShowMessage (ArrayList.    Items[i]); Student: = Tstudent (Tstudent.fromvariant (ArrayList.    Items[i]));  ShowMessage (IntToStr (student.id) + ', ' + utf8toansi (student.name) + ', ' + inttostr (student.age));  End ArrayList.  Free; {Keys:=ohashmap.    Keys; Values:=ohashmap.    Values; For I: = 0 to Keys.    Count-1 do begin key:=keys[i];    Value:=values[i]; ShowMessage (values.    List[i]);    ShowMessage (value);    Ohashmap: = Thashmap (thashmap.fromvariant (value)); ShowMessage (Ohashmap. Values[0].    properties[' name ']);    End }end;end.

  

From: http://blog.csdn.net/earbao/article/details/46428565

SOURCE Download: Http://pan.baidu.com/s/1eQ6KOcq

The PHPRPC uses an instance (which is true but cannot perform) function conflicts Gzdecode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.