Zend_xmlrpc Use example (easy to implement external interface)

Source: Internet
Author: User

ZEND_XMLRPC Use Instances

I. Introduction of ZEND_XMLRPC

1. Zend_xmlrpc_server:

Zend_xmlrpc_server according to? The specifications on the www.xmlrpc.com implement a fully functional XML-RPC server. It also implements the System.multicall () method that allows bulk transfer (boxcarring).

Personal understanding, Zend_xmlrpc_server can easily implement the function of WebService interface in PHP program, all external interfaces can be defined in the server file (add only externally developed interface), ensure the security of the interface and the security of the program.

2. Zend_xmlrpc_client:

XML-RPC the functionality of the service. Key features include automatic conversion of types between PHP and XML-RPC, service proxy objects (a server proxy object), and the introspection function of the access server (introspection capabilities).

It is understood that the interface defined in the Zend_xmlrpc_server can be easily invoked when used in other PHP programs using the interface in the Zend_xmlrpc_server defined in the previous program.

Second, the use of ZEND_XMLRPC

First we have to create a sever class, the name is custom. For example: I now create a myserver.php file in my project Zend_fraemwork,


The location of this myserver.php file is whatever you want, as long as it is under application (generally I will create a WebService folder for testing, so casually put).

The myserver.php file code is as follows:

<?php

require_once ' zend/xmlrpc/server.php ' ;

require_once application_path. ' \common\sendmail.php ' ;//First introduce an interface class to be developed under the project

&NBSP;

new zend_xmlrpc_server ();

$server->setclass ( ' SendMail ' , ' test ' ); /Create a namespace for test, and then put sendmail.php sendmail entire class put Zend_xmlrpc_server as external interface

echo $server->handle ();//output processing request result

This adds the entire sendmail.php class to the zend_xmlrpc_server, meaning that as long as I create the corresponding client instance with zend_xmlrpc_client in other programs, You can use this instance to access all the methods in the Sendmail.php class. $server can not only setclass, but also addfunction, that is, just adding a method in the class.

See here, you certainly can't wait to see how the other program to use Zend_xmlrpc_client to invoke the method in sendmail.php, OK, first see how to call it.

I created a new project named:zend_fraemwork1, and then under the default module, the Indexcontroller tried to try zend_xmlrpc_client to call, structure

As you can see, there is no sendmail.php file under the common folder under this project . and see how I call the Send method of this mail send class. The code is as follows:

$title =" test ";

$body =' This is a test of PHP Mail sent from Marktao !</ H1><a href= "#" > Please confirm </a> ';

$address = ' [email protected] ';

Try {

                     $client = new zend_xmlrpc_client ( ' http://192.168.1.104/zend_fraemwork/public/common/Myserver.php ' ); // This is my native ip : 192.168.1.104 Two projects are under the local site. According to url Instantiate the Zend_xmlrpc_client object.

$test = $client->getproxy (' test ');// getProxy() method takes an optional parameter as the namespace of the remote server that will be proxied. If this namespace is not specified, the default namespace is proxied

$test->__call (send, array($title, $body, $address));//Call __call method call in sendmail.php class. Send method to send the message. the array is used to pass parameters.

}Catch (Zend_xmlrpc_client_httpexception $ee) {

$ee->getmessage ();

}

In this way, we succeeded in invoking the sendmail.php in Zend_fraemwork in the project Zend_fraemwork1. The Send method in the class implements the mail sending function.

Iii. Summary

To summarize: First of all, we have to ensure that two projects can be communicated directly, that is to say, the network is a pass, and secondly, we have to create a class to provide external unified access, such as the above myserver.php; then we pass zend_xmlrpc_ in this class The server object takes the required class or method set or add in, so that it can be accessed at any time using the Zend_xmlrpc_client object in other projects.

In particular, it is important to introduce: in the Myserver.php class,

require_once ' zend/xmlrpc/server.php ';

And in classes that use Zend_xmlrpc_client objects, you must also use:

Require_once ' zend/xmlrpc/client.php ';

Finally, international practice, welcome to shoot Bricks!

Zend_xmlrpc Use example (easy to implement external interface)

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.