PHP SOAP Client
PHP's built-in SoapClient class communicates with SOAP web services. It automatically handles XML encoding/decoding from the WSDL definition.
PHP's built-in SoapClient class communicates with SOAP web services. It automatically handles XML encoding/decoding from the WSDL definition.
<?php
// Connect to SOAP service using WSDL
$client = new SoapClient("https://api.example.com/service?wsdl", [
"trace" => true,
"exceptions" => true,
]);
try {
// Call a remote method
$result = $client->getWeather(["city" => "London"]);
echo $result->temperature;
} catch (SoapFault $e) {
echo "SOAP Error: " . $e->faultstring;
}
// Debug
echo $client->__getLastRequest();
echo $client->__getLastResponse();
Enable trace => true when debugging SOAP calls — __getLastRequest() and __getLastResponse() show the raw XML.