-
-
Save ravahdati/ebdabec7ef66bc40877b8937900b0e6c to your computer and use it in GitHub Desktop.
PHP soap client example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setting SOAP configuration to disable WSDL caching and adjust socket timeout | |
ini_set('soap.wsdl_cache_enabled', 0); // Disable WSDL caching | |
ini_set('soap.wsdl_cache_ttl', 900); // Set the time to live for cached WSDL files to 900 seconds (15 minutes) | |
ini_set('default_socket_timeout', 15); // Set the default socket timeout to 15 seconds | |
// Define parameters for the SOAP request | |
$params = array('param1'=>$param1); | |
// Define the WSDL URL | |
$wsdl = 'http://service_url/method?WSDL'; | |
// Define SOAP client options | |
$options = array( | |
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/', | |
'style'=>SOAP_RPC, | |
'use'=>SOAP_ENCODED, | |
'soap_version'=>SOAP_1_1, | |
'cache_wsdl'=>WSDL_CACHE_NONE, // Disable WSDL caching | |
'connection_timeout'=>15, // Set connection timeout to 15 seconds | |
'trace'=>true, // Enable tracing for debugging purposes | |
'encoding'=>'UTF-8', | |
'exceptions'=>true, | |
); | |
try { | |
// Create a new instance of SoapClient using the defined WSDL and options | |
$soap = new SoapClient($wsdl, $options); | |
// Call the SOAP method with the specified parameters | |
$data = $soap->method($params); | |
} catch(Exception $e) { | |
// Handle any exceptions that occur during the SOAP request | |
die($e->getMessage()); // Output the error message and terminate the script | |
} | |
// Output the SOAP response for debugging purposes | |
var_dump($data); | |
// Terminate the script | |
die; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment