Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
10.1k views
in Technique[技术] by (71.8m points)

soap - PHP SoapClient constructor very slow

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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",
));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...