Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg

PHP : Function Reference : SOAP Functions

SOAP Functions


The SOAP extension can be used to write SOAP Servers and Clients. It supports subsets of » SOAP 1.1, » SOAP 1.2 and » WSDL 1.1 specifications.


This extension makes use of the » GNOME xml library. Download and install this library. You will need at least libxml-2.5.4.


This extension is only available if PHP was configured with --enable-soap.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 292. SOAP Configuration Options

Name Default Changeable Changelog
soap.wsdl_cache_enabled "1" PHP_INI_ALL Available since PHP 5.0.0.
soap.wsdl_cache_dir "/tmp" PHP_INI_ALL Available since PHP 5.0.0.
soap.wsdl_cache_ttl "86400" PHP_INI_ALL Available since PHP 5.0.0.
soap.wsdl_cache_limit "5" PHP_INI_ALL Available since PHP 5.1.5.

For further details and definitions of the PHP_INI_* constants, see the Appendix I, php.ini directives.

Here's a short explanation of the configuration directives.

soap.wsdl_cache_enabled boolean

Enables or disables the WSDL caching feature.

soap.wsdl_cache_dir string

Sets the directory name where the SOAP extension will put cache files.

soap.wsdl_cache_ttl int

Sets the number of seconds (time to live) that cached files will be used instead the originals.

soap.wsdl_cache_limit integer

Maximum number of in memory cached wsdl files

Predefined Classes







SoapHeader is a special low-level class for passing or returning SOAP headers. It's just a data holder and it does not have any special methods except its constructor. It can be used in the SoapClient->__soapCall() method to pass a SOAP header or in a SOAP header handler to return the header in a SOAP response.



SoapParam is a special low-level class for naming parameters and returning values in non-WSDL mode. It's just a data holder and it does not have any special methods except its constructor.






SoapVar is a special low-level class for encoding parameters and returning values in non-WSDL mode. It's just a data holder and does not have any special methods except the constructor. It's useful when you want to set the type property in SOAP request or response.


Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

SOAP_1_1 (integer)
SOAP_1_2 (integer)
SOAP_ENCODED (integer)
SOAP_LITERAL (integer)
SOAP_RPC (integer)
Added in PHP 5.1.0.
UNKNOWN_TYPE (integer)
XSD_STRING (integer)
XSD_BOOLEAN (integer)
XSD_DECIMAL (integer)
XSD_FLOAT (integer)
XSD_DOUBLE (integer)
XSD_DURATION (integer)
XSD_DATETIME (integer)
XSD_TIME (integer)
XSD_DATE (integer)
XSD_GYEAR (integer)
XSD_GDAY (integer)
XSD_GMONTH (integer)
XSD_BASE64BINARY (integer)
XSD_ANYURI (integer)
XSD_ANYXML (integer)
Added in PHP 5.1.0.
XSD_QNAME (integer)
XSD_NOTATION (integer)
XSD_TOKEN (integer)
XSD_LANGUAGE (integer)
XSD_NMTOKEN (integer)
XSD_NAME (integer)
XSD_NCNAME (integer)
XSD_ID (integer)
XSD_IDREF (integer)
XSD_IDREFS (integer)
XSD_ENTITY (integer)
XSD_ENTITIES (integer)
XSD_INTEGER (integer)
XSD_LONG (integer)
XSD_INT (integer)
XSD_SHORT (integer)
XSD_BYTE (integer)
XSD_NMTOKENS (integer)
XSD_ANYTYPE (integer)
SOAP_ENC_ARRAY (integer)
XSD_1999_TIMEINSTANT (integer)
XSD_1999_NAMESPACE (string)

Table of Contents

is_soap_fault — Checks if SOAP call was failed
SoapClient->__call() — Calls a SOAP function (deprecated)
SoapClient->__construct() — SoapClient constructor
SoapClient->__doRequest() — Performs a SOAP request
SoapClient->__getFunctions() — Returns list of SOAP functions
SoapClient->__getLastRequest() — Returns last SOAP request
SoapClient->__getLastRequestHeaders() — Returns last SOAP request headers
SoapClient->__getLastResponse() — Returns last SOAP response.
SoapClient->__getLastResponseHeaders() — Returns last SOAP response headers.
SoapClient->__getTypes() — Returns list of SOAP types
SoapClient->__setCookie() — Sets the cookie that will be sent with the SOAP request
SoapClient->__soapCall() — Calls a SOAP function
SoapFault->__construct() — SoapFault constructor
SoapHeader->__construct() — SoapHeader constructor
SoapParam->__construct() — SoapParam constructor
SoapServer->addFunction() — Adds one or several functions those will handle SOAP requests
SoapServer->__construct() — SoapServer constructor
SoapServer->fault() — Issue SoapServer fault indicating an error
SoapServer->getFunctions() — Returns list of defined functions
SoapServer->handle() — Handles a SOAP request
SoapServer->setClass() — Sets class which will handle SOAP requests
SoapServer->setPersistence() — Sets persistence mode of SoapServer
SoapVar->__construct() — SoapVar constructor
use_soap_error_handler — Set whether to use the SOAP error handler and return the former value

Code Examples / Notes » ref.soap


wow, actually a cool program and soap is new for me.
I found out some interessting things i can not debug because the scripts exit without any error messages or notes. :-(
you may have problems with the memory and/or especially on "shared servers" when server load is high.
sometimes the script does the job, sometimes it just stopping at any unknown point.
these are the steps my script does:
* get data from remote server ( ~ 4.5 MB)
* parsing requested object and store the data in a database.
the return with debug messages was intressting:
-> check Mem limit: 30M
-> $client = new new SoapClient($url_wsdl, $options);
-> Memory usage: 185888
-> $client->[requested_method_to_get_data]();
-> check: __getLastResponseHeaders() - after:
-> HTTP/1.1 200 OK // remote server is fine with me :-)
-> Content-Length: 4586742  // I got the data
-> check: Memory usage now: 23098872 // ups !!! this can't be true!!
so, and if now someone on the server takes the rest of RAM  the walk thought the data breaks :-(
so, i need to store the xml tree ($client->client->__last_response) and parsing it by the classical way. (if you would request more RAM, you may get in trouble with the admin if you run a script like this more often! (on shared servers)


Wondering why the function you just added to your WSDL file is not available to your SOAP client? Turn off WSDL caching, which (as the documentation says) is on by default.
At the top of your script, use:
$ini = ini_set("soap.wsdl_cache_enabled","0");


wokan at cox dot net is incorrect about the security of URI-passed values to HTTPS URIs.  HTTPS connections are HTTP inside SSL -- all of the HTTP traffic, including the request, are encrypted.

jochen dot munz

When encountering an error message like this
[faultstring] => Function ("yourMethod") is not a valid method for this service
although it is present in the WSDL etc., be aware that PHP caches the wsdl locally for better performance. You can disable the caching via php.ini/.htaccess completely or remove the cache file (/tmp/wsdl-.. if you are on Linux) to force regeneration of it.

When compiling SOAP support for PHP 5.2.0 it was not sufficient to use "--with-soap" in the "./configure" statement. I also had to include "--enable-soap" to get it work.


To enable SoapClient on Windows, simply add a line:
in php.ini in the extensions section.


To debug a SOAP service using SoapServer(), a WSDL file and Zend Studio Client/Server, you have to append ?start_debug=1&debug_port=10000 to the service location:
--- snip ---
... method / service definition ....
<service name="SOAPService">
--- snap ---


Those having to work with Paypal's api and using PHP5 SOAP:


this is something i wrote to access a webservice with php4


One good tutorial on using this extension is on IBM web site:
"Using the PHP 5 SOAP extension to consume a WebSphere Web service" /developerworks/library/os-phpws/?ca=dgr-lnxw06PHP5soap

norman clarke
Note that if you should need to set the timeout for your soap request,  you can use ini_set to change the value for the default_socket_timeout. I previously used NuSOAP, whose soap client class has a timeout option, and it took me a while to figure out that PHP's soap uses the same socket options as everything else.


It's not good security practice to pass the username and password in the URI when the point of SSL is to prevent that information from being intercepted.  Putting that information in the URI makes it interceptable.  HTTPS-Posted values are safe because values passed in the headers are sent after the SSL handshake has been completed.


It took me a while to properly establish a password protected client connection via https on windows/apache1.3. Here my little guide:
1. The SOAP extension isn't activated by default (PHP5 RC1). Just add "extension=php_soap.dll" to the php.ini and don't forget to set the extension_dir properly (in most cases "c:\php\ext").
2. Add "extension=php_openssl.dll" to the php.ini. This module depends on libeay32.dll and ssleay32.dll - copy them from your php folder to your system32 folder.
3. Restart apache
4. The sourcecode
$client = new SoapClient("", array(
   "login"      => "yourLogin",
   "password"   => "yourPassword",
   "trace"      => 1,
   "exceptions" => 0));
print "<pre>\n";
print "Request: \n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response: \n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";
Currently it seems to be necessary to add your login and password both in the uri and in the options array. Not sure if this is the expected behavior.

marcio annunciato

In case your soap response containts an ampersand, in certain cases you might get an "unterminated entity reference" warning and data might appear truncated (related to bug #36795?). Maybe there is a more formal fix or setting, but since I couldn't find anything I came with the following:
class MySoapClient extends SoapClient {
   function __doRequest($request, $location, $action, $version) {
    $res = parent::__doRequest($request, $location, $action, $version);
       $resx = str_replace('&amp;', '&amp;amp;', $res);
       return ($resx);

jim plush

If you're trying to use the SOAP Extension over SSL with a custom PEM file you need to do this:
$client->_local_cert = "C:\\path\myCert.pem";


If you're having problems calling a .NET web service, see the comments over on (the __soapCall method).


If you want to use soap over https, you *must* compile php with the configure option with-openssl or you will have the error "[HTTP] SSL support not available in this build" while trying to use the web services over SSL


If you want to build a Soap Server for Microsoft Office's client (like Microsoft Office Research Service) you need to rewrite SOAP's namespaces :
// (...)
$server = new SoapServer($wsdl, array('uri' => $uri, 'classmap' => $classmap));
function callback($buffer)
   $s = array('<ns1:RegistrationResponse>', 'ns1:', 'xmlns:ns1="urn:Microsoft.Search"');
   $r = array('<RegistrationResponse xmlns="urn:Microsoft.Search">', '', '');
  return (str_replace($s, $r, $buffer));
// (...)
There are a complete example at this URL :

olaf krische

If you use SSL with a cert and password authentication:
$wsdl = "";
$pass = 'a password';
$certFile = "./mycert.pem";
 $client = new SoapClient($wsdl,
    'local_cert' => $certFile,
    'passphrase' => $pass
If you have problems with the certfile like this:
 Warning: SoapClient::__construct(): Unable to set local cert chain file `./mycert.pem'; Check that your cafile/capath settings include details of your certificate and its issuer in productinfo.php on line 27
then the certFile is probably in the "wrong format" (the wrong format for php maybe). It worked for me, when i appended the content of the private key file and the certificate file to a single file "mycert.pem":
 cat mycert.key >mycert.pem # mycert.key was the private key
 cat mycert.crt >>mycert.pem # mycert.crt was the signed certificate
Thanks to an author somewhere, who pointed to "curl --cert", where this little "so unimportant" dependency has been mentioned.


If you dont want to manually maintain the classmap, make sure you use the same names for your PHP object classes and your WSDL complexTypes, and use the following code:
$classmap = array();
$tmpClient = new SoapClient("soapserver.wsdl");

foreach($tmpClient->__getTypes() as $type)
$array = split(" ", $type);
if($array[0] == "struct" && class_exists($array[1]))
$classmap[$array[1]] = $array[1];

$server = new SoapServer("soapserver.wsdl", array("classmap" => $classmap));


If you are scratching your head why NuSOAP not working on PHP 5.x , the reason is this built-in SOAP Extenstion uses same soapclient() class name as Nusoap.
replace 'soapclient' with 'soapclient_xxx'  in nusoap.php and you are good to go...

herman hiddema

I recently found that when using SoapClient with client certificates (the 'local_cert' and 'passphrase' options), PHP needs to have CURL enabled. (At least with PHP 5 and Apache on Windows)
I kept getting errors like this:
Unable to set local cert chain file `filename.pem'; Check that your cafile/capath settings include details of your certificate and its issuer in somescript.php on line ##
I tried everything I could find on the net (correct .pem format, constructing and passing my own stream context, etc) but nothing would work. Enabling CURL (by uncommenting extension=php_curl.dll in php.ini) instantly caused my client to work.


I hope this will save someone time. When developing and testing your SOAP server, remember to disable WSDL caching in BOTH client and server:
$ini = ini_set("soap.wsdl_cache_enabled", 0);

rui martins

Here's an example on how to pass ArrayOfAnyType arguments
containing complex types.
Suppose your WSDL file defines "" as the default namespace and a complex type "SomeComplexType".
If you want to call a WebServices which takes an ArrayOfAnyType argument of "SomeComplexType"s you need to perform the following:
// complexTypes being an array containing several instances of SomeComplexType
myWSParameter = array();
foreach (complexTypes as ct)
  // Don't misspell the type or the namespace. Also note that php won't assume the default namespace defined in the WSDL file.
  myWSParameter []= new SoapVar(ct, 0, "SomeComplexType", "");
On the other hand, when a WebService returns an ArrayOfAnyType you have to do the following to access each of its elements.
// Here, we will be echoing each return item
$res = $someWS->myFunction($myArgs)
// If only one element is returned, an array won't be built
if (is_array(myFunctionResult->anyType))
  foreach (myFunctionResult->anyType as $soapVar)
     echo $soapVar->enc_value;
  echo myFunctionResult->anyType->enc_value;
This has all been tested using a .NET WebService.

03-dec-2004 03:06

here i found a good collection of tutorials all around soap/web services and/or rss:


Here are 73 test cases that detail the kinds of schemas that PHP5 currently supports and the structures you are expected to plug into them for the return value from your services.   Much better than trying to guess!
You can cycle through the listings by changing the main index in the URL below,  rather than go in and out of the pages
I downloaded the whole thing with this,  CVS might work too.
With them all downloaded I just browse them with Textpad.


Heads up for anyone using PHP Soap + Sessions + PEAR DB classes.
Every time you make a call, via the soap client to your web service, your PEAR DB session is put to sleep and it doesnt by default wake upon the next request.
To fix this I simply called my particular database close call ifx_close() below my $soap->handle();


Having trouble passing complex types over SOAP using a PHP SoapServer in WSDL mode?  Not getting decoded properly?  This may be the solution you're looking for!
When using ComplexType in the schema portion of the WSDL file, You need use an additional step to tell PHP SOAP how to encode the objects.  The first method would be to explicitely encapsulate the object in a SoapVar object - telling PHP to use generalized SOAP encoding rules (which encodes all ComplexTypes as Structs).  This won't work, though, if the client is expecting the objects to be encoded according to the WSDL's schema.  So, The actual way to do this is:
* First, define a specific PHP class which is actually just a data structure holding the various properties, and the appropriate  ComplexType in the WSDL.
class MyComplexDataType {
    public $myProperty1;
    public $myProperty2;
<complexType name="MyWSDLStructure">
   <element name="MyProperty1" type="xsd:integer"/>
   <element name="MyProperty2" type="xsd:string"/>
* Next, Tell the SoapServer when you initialize it to map these two structures together.
$classmap = array('MyWSDLStructure' => 'MyComplexDataType');
$server = new SoapServer("http://MyServer/MyService.wsdl", array('classmap' => $classmap))
* Finally, have your method return an instance of your class directly, and let the SoapServer take care of encoding!
public function MySoapCall() {
    $o = new MyComplexDataType();

    $o->myProperty1 = 1;
    $o->myProperty2 = "MyString";

    return $o


For those working from a wsdl full of complex types that just want a class structure to hang your code on and not worry about typing in long parameter lists (or creating a script to do so): wsdl2php is a wonderful time-saver. Gets a structure going so you can go in and add what validation and special data munging you need:
Big up yourself, Knut.


For those wondering on how to set attributes on nodes with PHP5 SOAP, it would be done as such:
<... soap env/header>
<foo bar="blah">12345</foo>
array("foo" => array("_" => 12345, "bar" => "blah"));

matthew glubb

For anyone wondering why they are getting a "DTD are not supported by SOAP" fault string. It is because you are probably being returned an HTML page due to an internal server error, 404, etc.
Refer to the documentation for SoapClient->__getLastResponse in order to see what returned by the server.


A note for ppl who use certificates with SOAP under a Windows config: it seems to be required to give the full path to the certificate file - and don't prepend 'file://' :
$wsdl = "test.wsdl";
$local_cert = "c:\htdocs\mycert.pem";
$passphrase = "xyz";
$client = new SoapClient($wsdl, array('local_cert' => $local_cert, 'passphrase' => $passphrase);

Change Language

Follow Navioo On Twitter
.NET Functions
Apache-specific Functions
Alternative PHP Cache
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BBCode Functions
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Class/Object Functions
Classkit Functions
ClibPDF Functions [deprecated]
COM and .Net (Windows)
Crack Functions
Character Type Functions
Cybercash Payment Functions
Credit Mutuel CyberMUT functions
Cyrus IMAP administration Functions
Date and Time Functions
DB++ Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
enchant Functions
Error Handling and Logging Functions
Exif Functions
Expect Functions
File Alteration Monitor Functions
Forms Data Format Functions
Fileinfo Functions
filePro Functions
Filesystem Functions
Filter Functions
Firebird/InterBase Functions
Firebird/Interbase Functions (PDO_FIREBIRD)
FriBiDi Functions
FrontBase Functions
FTP Functions
Function Handling Functions
GeoIP Functions
Gettext Functions
GMP Functions
gnupg Functions
Haru PDF Functions
hash Functions
Hyperwave Functions
Hyperwave API Functions
i18n Functions
IBM Functions (PDO_IBM)
iconv Functions
ID3 Functions
IIS Administration Functions
Image Functions
Imagick Image Library
Informix Functions
Informix Functions (PDO_INFORMIX)
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
JSON Functions
LDAP Functions
libxml Functions
Lotus Notes Functions
LZF Functions
Mail Functions
Mailparse Functions
Mathematical Functions
MaxDB PHP Extension
MCAL Functions
Mcrypt Encryption Functions
MCVE (Monetra) Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Microsoft SQL Server Functions
Microsoft SQL Server and Sybase Functions (PDO_DBLIB)
Mohawk Software Session Handler Functions
mSQL Functions
Multibyte String Functions
muscat Functions
MySQL Functions
MySQL Functions (PDO_MYSQL)
MySQL Improved Extension
Ncurses Terminal Screen Control Functions
Network Functions
Newt Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Object property and method call overloading
Oracle Functions
ODBC Functions (Unified)
ODBC and DB2 Functions (PDO_ODBC)
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions [deprecated]
Oracle Functions (PDO_OCI)
Output Control Functions
Ovrimos SQL Functions
Paradox File Access
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF Functions
PDO Functions
Phar archive stream and classes
PHP Options&Information
POSIX Functions
Regular Expression Functions (POSIX Extended)
PostgreSQL Functions
PostgreSQL Functions (PDO_PGSQL)
Printer Functions
Program Execution Functions
PostScript document creation
Pspell Functions
qtdom Functions
Rar Functions
GNU Readline
GNU Recode Functions
RPM Header Reading Functions
runkit Functions
SAM - Simple Asynchronous Messaging
Satellite CORBA client extension [deprecated]
SCA Functions
SDO Functions
SDO XML Data Access Service Functions
SDO Relational Data Access Service Functions
SESAM Database Functions
PostgreSQL Session Save Handler
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
SQLite Functions (PDO_SQLITE)
Secure Shell2 Functions
Statistics Functions
Stream Functions
String Functions
Subversion Functions
Shockwave Flash Functions
Swish Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
Unicode Functions
URL Functions
Variable Handling Functions
Verisign Payflow Pro Functions
vpopmail Functions
W32api Functions
WDDX Functions
win32ps Functions
win32service Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XMLReader functions
XMLWriter Functions
XSL functions
XSLT Functions
YAZ Functions
YP/NIS Functions
Zip File Functions
Zlib Compression Functions
eXTReMe Tracker