PHP enterprise-level application-WebService Extension

Source: Internet
Author: User
Tags pings

Brief Introduction: This is a detailed page of the PHP enterprise-level application's WebService, which introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 323134 'rolling = 'no'>

PHP enterprise-level application WebService

Ping service: the blog program provides a notification mechanism to publish the updated information of the blog to the website that provides the ping service in the first time. I did some research when writing the aggregation.

Let's look at the standard first.

This is a standard Ping service. It uses XMLRPC to transmit data. The code description is not needed because the annotation is so detailed. The XMLRPC method is enabled in PhP5.

Client. php

Reference content is as follows:

<? PHP
$ Host = 'zxsv ';
$ Port = 80;
$ Rpc_server = '/test/xmlrpc_server.php ';
$ Title = 'zxsv ';
$ Server = 'HTTP: // zxsv/test /';
$ RSS = 'HTTP: // zxsv/test/RSS. php ';
// Weblogupdates. Ping Method
$ Ping = xmlrpc_encode_request ('weblogupdates. ping', array ($ title, $ server ));
// Weblogupdates. extendedping Method
$ Extendedping = xmlrpc_encode_request ('weblogupdates. extendedping', array ($ title, $ server, $ RSS ));
// Call the rpc_client_call function to send all requests to the XML-RPC server for information
$ Response = rpc_client_call ($ host, $ port, $ rpc_server, $ ping );
$ Split = '<? XML version = "1.0" encoding = "iso-8859-1"?> ';
$ Xml = explode ($ split, $ response );
$ Xml = $ split. array_pop ($ XML );
$ Response = xmlrpc_decode ($ XML );
// Output the information obtained from the RPC server
Print_r ($ response );
/**
* Function: provides a function to the client to connect to the XML-RPC server.
* Parameters:
* $ Host the host to be connected
* $ Port: port used to connect to the host
* $ Rpc_server XML-RPC server files
* $ XML request information encapsulated by request
* Return: if the connection succeeds, XML Information returned by the server is returned. If the connection fails, false is returned.
*/
Function rpc_client_call ($ host, $ port, $ rpc_server, $ request ){
$ Fp = fsockopen ($ host, $ port );
$ Query = "post $ rpc_server HTTP/1.0 \ nuser_agent: XML-RPC client \ nhost :". $ host. "\ ncontent-type: text/XML \ ncontent-length :". strlen ($ request ). "\ n ". $ request. "\ n ";
If (! Fputs ($ FP, $ query, strlen ($ query ))){
$ Errstr = "write error ";
Return false;
}
$ Contents = '';
While (! Feof ($ FP )){
$ Contents. = fgets ($ FP );
}
Fclose ($ FP );
Return $ contents;
}
?>

Server. php

Reference content is as follows:

<? PHP
/**
* Function: the function provided to the RPC client.
* Parameters:
* $ Function to be called by the method Client
* $ Params parameter array of the function to be called by the client
* Return: return the specified call result.
*/
Function rpc_server_extendedping ($ method, $ Params ){
$ Title = $ Params [0];
$ Server = $ Params [1];
$ RSS = $ Params [2];
// Intermediate judgment. $ xml_rpc_string is returned successfully.
$ Xml_rpc_string = array ('flerror' => false, 'message' => 'Thanks for the ping .');
Return $ xml_rpc_string;
}
Function rpc_server_ping ($ method, $ Params ){
$ Title = $ Params [0];
$ Server = $ Params [1];
// Intermediate judgment. $ xml_rpc_string is returned successfully.
$ Xml_rpc_string = array ('flerror' => false, 'message' => 'Thanks for the ping .');
Return $ xml_rpc_string;
}
// Generate a XML-RPC on the server side
$ Xmlrpc_server = xmlrpc_server_create ();
// Register a method called by the server, rpc_server, which actually points to the rpc_server_extendedping Function
Xmlrpc_server_register_method ($ xmlrpc_server, "weblogupdates. extendedping", "rpc_server_extendedping ");
Xmlrpc_server_register_method ($ xmlrpc_server, "weblogupdates. Ping", "rpc_server_ping ");
// Accept XML data post from the client
$ Request = $ http_raw_post_data;
// Print_r ($ request );
// Execute the XML request to call the client and obtain the execution result
$ Xmlrpc_response = xmlrpc_server_call_method ($ xmlrpc_server, $ request, null );
// Output the result XML after function processing
Header ('content-type: text/xml ');
Echo $ xmlrpc_response;
// Destroy XML-RPC server resources
Xmlrpc_server_destroy ($ xmlrpc_server );
?>

Class write, with bugs

Reference content is as follows:

<? PHP
Class pings {
Public $ xmlrpc_server;
Public $ xmlrpc_response;
Public $ methodname;
Public Function _ construct (){
// Generate a XML-RPC on the server side
$ This-> xmlrpc_server = xmlrpc_server_create ();
$ This-> Run ();
}

// Register a method called by the server, rpc_server, which actually points to the Ping function
Public Function rpc_server (){
$ This-> methodname =! $ This-> methodname? 'Weblogupdates. extendedping': 'weblogupdates. ping ';
Xmlrpc_server_register_method ($ this-> xmlrpc_server, $ this-> methodname, array (_ class __, "ping "));
}
/**
* Function: the function provided to the RPC client.
* Parameters:
* $ Function to be called by the method Client
* $ Params parameter array of the function to be called by the client
* Return: return the specified call result.
*/
Public Function Ping ($ method, $ Params ){
$ This-> Title = $ Params [0];
$ This-> Server = $ Params [1];
$ This-> RSS = $ Params [2];
$ This-> tag = $ Params [3];
// $ A = $ this-> title? $ This-> Update ():'';
$ String = array ('flerror' => false, 'message' => 'Thanks for the ping. ', 'gal' => "you agree that use of the blueidea.com Ping Service is governed by the terms of use found at www.blueidea.com. ");
Return $ string;
}

Public Function Update (){
Echo 'here are some of the updated conditions ';
}

Public Function run (){
$ This-> rpc_server ();
$ Request = isset ($ globals ["http_raw_post_data"])? File_get_contents ("PHP: // input"): $ globals ["http_raw_post_data"];
$ This-> xmlrpc_response = xmlrpc_server_call_method ($ this-> xmlrpc_server, $ request, null );
// Output the result XML after function processing
Header ('content-type: text/xml ');
Echo $ this-> xmlrpc_response;
}

// Destroy XML-RPC server resources
Public Function _ destruct (){
Xmlrpc_server_destroy ($ this-> xmlrpc_server );
}
}
$ OBJ = new PINGS ();
?>

The two most common WebService methods are written together.

More articles on "php enterprise-level application-WebService"

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/323134.html pageno: 16.

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.