zoukankan      html  css  js  c++  java
  • PHP安装SOAP扩展

    PHP安装SOAP扩展

    1.安装php-soap:
    yum install php-soap -y
    
    2.在PHP的编译参数中加入--enable-soap,如:
    ------
    ./configure --prefix=/usr/local/php-5.2.12 
    	--with-config-file-path=/usr/local/php-5.2.12/etc 
    	--enable-fastcgi --enable-force-cgi-redirect --with-curl 
    	--with-gd --with-ldap --with-snmp --enable-zip --enable-exif 
    	--with-pdo-mysql --with-mysql --with-mysqli 
    --enable-soap
    ------
    

      

    PHP建立SOAP服务器

    建立函数文件

    这里我们建立一个soap_function.php的文件,用于定义公开给请求的调用的函数
    * file name:soap_function.php 
    ------
    
    <?php
    
    function get_str($str){
            return 'hello '.$str;
    
    }
    
    function add_number($n1,$n2){
            return $n1+$n2;
    
    }
    
    ?>
    
    ------
    	
    

      

    建立服务,注册函数

    有了上步操作,我们还要建立一个SOAP服务并且将定义好的函数注册到服务中
    
     * file name:soap_service.php 
    ------
    <?php
    
    include_once('soap_function.php');//导入函数文件
    
    $soap = new SoapServer(null,array('uri'=>'http://zenw.org')); //建立SOAP服务实例
    $soap->addFunction('get_str');
    $soap->addFunction('sum_number');
    //或者可以 $soap->addFunction(array('get_str','sum_number'));
    
    $soap->addFunction(SOAP_FUNCTIONS_ALL); //常量SOAP_FUNCTIONS_ALL的含义在于将当前脚本所能访问的所有function(包括一些系统function)都注册到服务中
    $soap->handle(); //SoapServer对象的handle方法用来处理用户输入并调用相应的函数,最后返回
    
    ?>
    

      

    ------ 到这里,一个SoapServer就搭建好了,剩下的就是如何请求她了

    PHP建立SOAP客户端请求

    *  file name:soap_client.php 
    ------
    <?php
    
    $client = new SoapClient(null,array('location'=>"http://192.168.3.229/soap/soap_service.php", //在SOAP服务器建立环节中建立的soap_service.php的URL网络地址
                                        'uri'=>'http://zenw.org'));
    
    $str = 'zenwong';
    
    echo "get str is :".$client->get_str($str);
    echo "<br />";
    echo 'sun number is:'.$client->sun_number(9,18);
    
    ?>
    

      

    ------
  • 相关阅读:
    Asp.net获取客户端的IP地址排除::1
    EF 筛选列包含NULL会报错
    layUI关于table编辑列支持方向键功能
    .NET CORE 发布IIS问题收集
    VS2019最新源代码管理工具+附下载地址
    关于Mysql可视化工具Navicat Premium12激活使用【亲测】
    经典SQL 语句
    事务的四种隔离级别 [转载]
    HTML 特殊符号编码对照表
    github本地文件Push到仓库
  • 原文地址:https://www.cnblogs.com/liushiyong1/p/3498389.html
Copyright © 2011-2022 走看看