php SOAP non-WSDL 模式

52 篇文章 0 订阅

PHP 的 SOAP 扩展可以用来提供和使用 Web Services。

* requires

  • php: >= 5.5
  • ext-soap: *

* php.ini

extension=soap

[soap]
; Enables or disables WSDL caching feature.
; http://php.net/soap.wsdl-cache-enabled
soap.wsdl_cache_enabled=1

; Sets the directory name where SOAP extension will put cache files.
; http://php.net/soap.wsdl-cache-dir
soap.wsdl_cache_dir="/tmp"

; (time to live) Sets the number of second while cached file will be used
; instead of original one.
; http://php.net/soap.wsdl-cache-ttl
soap.wsdl_cache_ttl=86400

; Sets the size of the cache limit. (Max. number of WSDL files to cache)
soap.wsdl_cache_limit=5

* 目录结构

*  index.php (client)

<?php
// php -S 0.0.0.0:8086
try {
    $client = new SoapClient(null, [
        'location' => 'http://localhost:8086/hello_service_wsdl.php',
        'uri' => 'http://localhost:8086'
    ]);
    $result =  $client->__soapCall('greet', [
        new SoapParam('world', 'name')
    ]);
    printf("%s!", $result);
} catch (Exception $e) {
    printf("%s",$e->__toString());
}

* hello_service_wsdl.php (server)

<?php
/**
 * Created by PhpStorm.
 * User: mingzhanghui
 * Date: 2018-09-12
 * Time: 15:04
 */
function greet($param) {
    $value  = 'Hello ' . $param;
    return new SoapParam($value, 'greetReturn');
}

$server = new SoapServer(null, [
   'uri' => 'http://localhost:8086/helloService'
]);

$server->addFunction('greet');
$server->handle();

* start.bat

php -S 0.0.0.0:8086

* test

E:\code\php\test\soap>php index.php
Hello world!
 

* 查找组件

 https://packagist.org/?query=soap

https://packagist.org/packages/artisaninweb/laravel-soap

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fareast_mzh

打赏个金币

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值