Use of XML-RPC functions in php5

Source: Internet
Author: User
Tags manual php and strlen
I have read several award-winning works on web architecture, and I feel deeply touched by the fact that xml and php are more and more integrated, almost all works in IT use xml in design ..... -_-! A lot of times out of date. I suggest you go and have a look at it. So I am crazy about learning about php and xml in the past few days.
This one encountered the XML-RPC service, the information that can be found on the Internet is not much, and most of them are used by other third parties with php Development of XML-RPC class, however, it seems that there are not many xmlrpc functions that come with php5 (currently a test module), but I personally prefer native things and I will study it myself.
An example is provided in the manual, but it does not support Chinese characters and does not tell the client how to process the result after returning the result. after a long time, I finally figured it out. In fact, it is easy for him to support Chinese, and almost no additional work is required.
The following is his original example (which can be found in the manual ):
/* Clienttest. php */
<? Php
Function do_call ($ host, $ port, $ request ){
    
$ Fp = fsockopen ($ host, $ port, $ errno, $ errstr );
$ Query = "POST/servertest. php HTTP/1.0User _ Agent: My Egg ClientHost :". $ host. "Content-Type: text/xmlContent-Length :". strlen ($ request ). "". $ request. "";
If (! Fputs ($ fp, $ query, strlen ($ query ))){
$ Errstr = "Write error ";
Return 0;
     }
$ Contents = '';
While (! Feof ($ fp )){
$ Contents. = fgets ($ fp );
     }
Fclose ($ fp );
Return $ contents;
}
$ Host = 'localhost ';
$ Port = 80;
$ Request = xmlrpc_encode_request ('cycle', 'egg ');
$ Response = do_call ($ host, $ port, $ request );
/* Do something with $ response, e.g. print it */
?>
/* Servertest. php */
<? Php
Function lifecycle ($ method, $ params ){
/* $ Method = 'cycle', $ params = (array of) request parameter (s); $ data is also passed from xmlrpc_server_call_method, if we had any data to pass */

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.