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

* 目录结构

php SOAP non-WSDL 模式_.net

*  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