I am new to Web Services. I am experiencing inexplicably random SoapClient constructor execution times. Usually the call takes about 10 seconds. Sometimes it takes less than one second, but this occurrence is less frequent.
PHP SoapClient Constructor extremely slow
PHP: SoapClient constructor is very slow (takes 3 minutes)
Connecting to WCF Web Service is inexplicably slow
My situation is similar to those in the above threads but the solutions provided in them didn't resolve my issue.
// config params
$params = array(
'trace' => 1,
'soap_version' => SOAP_1_1,
'cache_wsdl' => WSDL_CACHE_MEMORY
);
// this call takes about 10 seconds to remote WSDL
$soap_client = new SoapClient(WSDL_URL,$params);
I have played with the different wsdl caching parameters and found WSDL_CACHE_MEMORY to be the fastest. When using the other caching options, the call takes about 25 seconds on average.
I am not using multiple users.
I have changed the wsdl_cache_dir to a Windows friendly directory in php.ini.
My question is two-fold:
Why is the SoapClient constructor seemingly random in how long it takes to execute? Why does it usually take longer but then sometimes only takes a split second? Is there a test I can perform to learn why it's behaving this way?
Should I be caching/saving the SoapClient object or resource so that when my page visitors move from page to page I don't need to create a new SoapClient and re-parse the WSDL again? What's the recommended approach to accomplish that?
Any help or nudge in the right direction would be much obliged. Thank you.
TTL defines how long the WSDL lives in cache.
soap.wsdl_cache_ttl integer
Sets the number of seconds (time to live) that cached files will be used instead of the originals.
http://www.php.net/manual/en/soap.configuration.php#ini.soap.wsdl-cache-ttl
Also you could download the WSDL to the local filesystem and use it as source for SoapClient
$client = new SoapClient("file://path/wsdl.file", array(
'location' => "http://domain/ws-endpoint",
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With