Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP SoapClient constructor very slow

Tags:

php

soap

wsdl

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:

  1. 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?

  2. 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.

like image 584
cre8value Avatar asked Mar 28 '13 21:03

cre8value


1 Answers

Check the TTL

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

Store the WSDL locally

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",
));
like image 105
Maks3w Avatar answered Oct 17 '22 10:10

Maks3w