It is old and can be replaced with REST API web services

In Ubuntu/Debian you can install with:

apt-get install php7.0-soap



PHP SOAP server


<?php    # amirWS.php
function AmirFunctionEchoo($echo){
    return "ECHO: ".$echo;
#The “uri” value is just an unique identification, used as the namespace for the response message. 
$server = new SoapServer(null,array('uri' => "http://localhost/res"));





The page generator client


<?php   # amirWSclient.php

$echo = $_GET[‘input’];

print “<h2>Echo Web Service</h2>”;
print “<form action=’simple_client.php’ method=’GET’/>”;
print “<input name=’input’ value=’$echo’/><br/>”;
print “<input type=’Submit’ name=’submit’ value=’GO’/>”;
print “</form>”;
print “</form>”;

// SoapClient (null if non-WSDL mode is used, array());

//location is the URL of the SOAP server to send the request to, and

//uri is the target namespace of the SOAP service.  

if($echo != ”){
$client = new SoapClient(



‘location’ => “”,

‘uri’ => “urn://”)


$result = $client->__soapCall(“AmirFunctionEchoo“,array($echo));

print $result;



Example 2 Using class MySoapServer




// server
class MySoapServer
  public function getMessage()
    return 'Hello,World!';
  public function addNumbers($num1,$num2)
    return $num1+$num2;


$options= array(‘uri’=>’http://localhost/test’);

$server=new SoapServer(NULL,$options);

# setClass() will automatically add all the functions from


# DO NOT Use addFunction()because it tells it to look for a function on its own





# soap client

$options= array( ‘location’ => ‘http://localhost/debug.php’, ‘uri’ => ‘http://localhost/everth’ );

$client=new SoapClient(NULL,$options);

echo $client->getMessage();


echo $client->addNumbers(3,5);

# 8


Example 3

<?php # AmirServer.php

function AmirFunc($someone) { 
   return "Hello " . $someone . "!";
   $server = new SoapServer(null, 
      array('uri' => "urn://"));
   $server->addFunction("AmirFunc");   #Using addFunction() tells it to look for a function named AmirFunc() on its own $server->handle(); ?>


<?php # AmirClient.php

   $client = new SoapClient(null, array(
      'location' => "http://localhost/AmirServer.php",
      'uri'      => "urn://",
      'trace'    => 1 ));

   $return = $client->__soapCall("AmirFunc",array("nice."));
   echo("\nReturning value of __soapCall() call: ".$return);

   echo("\nDumping request headers:\n" 

   echo("\nDumping request:\n".$client->__getLastRequest());

   echo("\nDumping response headers:\n"

   echo("\nDumping response:\n".$client->__getLastResponse());

 Then run AmirClient.php



echo "<?php phpinfo(); ?>"






Since 11 April 2023: 862 total views,  13 views today