訪問:php
http://www.debug.com/php-soap-demo.php?client=22web
結果:apache
apache:bash
<VirtualHost _default_:80> DocumentRoot "E:\www\test\debug" ServerName www.debug.com ServerAlias debug.com <Directory "E:\www\test\debug"> Options -Indexes +FollowSymLinks +ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost>
code:: php-soap-demo.php併發
<?php /*-------------*/ if(isset($_GET['client'])){//fixme client index - 客戶端入口 try{ // non-wsdl方式調用web service // 建立 SoapClient 對象 $soap = new SoapClient(null,array('location'=>"http://www.debug.com/php-soap-demo.php",'uri'=>'php-soap-demo.php')); // 調用函數 $result1 = $soap->getName(); $result2 = $soap->__soapCall("getHost",array()); echo $result1."<br/>"; echo $result2; } catch(SoapFault $e){ echo $e->getMessage(); }catch(Exception $e){ echo $e->getMessage(); } } /*-------------*/ //fixme server index //request Class Class Request { //base config protected $config = [ 'app'=> '徐鍋博客!', 'host'=>'localhost:3038' ]; //construct public function __construct($config= []) { $this->config = array_merge($this->config,$config); } //get attr config public function __get($name){ return $this->config[$name]; } //soap method public function getName() { return $this->app; } //soap method public function getHost() { return $this->host; } } // Create SoapServer OBJECT $server = new SoapServer(null,array("location"=>"http://www.debug.com/php-soap-demo.php","uri"=>"php-soap-demo.php")); // EXPORT Request 類中的所有函數 $server->setClass("Request"); // 處理一個SOAP請求,調用必要的功能,併發送回一個響應。 $server->handle();