note 80852 added to function.soap-soapclient-dorequest
| From: | james dot ellis at gmail dot com | Date: | Mon, 04 Feb 2008 12:12:38 +0000 |
| Subject: | note 80852 added to function.soap-soapclient-dorequest | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135755@lists.php.net to get a copy of this message | ||
If your application interacts with SOAP services and you wish to cache the responses for consumption
later, then overriding SoapClient::__doRequest is the way to go.
For instance, if you know that the information presented doesn't change that often and you
don't want to do a superfluous HTTP request, you can grab a response from a local cache and let
SoapClient do the transformation to PHP data types.
<?php
class YourNamespace_SoapClient_Local extends SoapClient {
protected $cacheDocument = "";
public function __construct($wsdl, $options) {
parent::__construct($wsdl, $options);
}
/**
* SetCacheDocument() sets the previously cached document contents
*/
public function SetCacheDocument($document) {
$this->cacheDocument = $document;
}
/**
* __doRequest() overrides the standard SoapClient to handle a local request
*/
public function __doRequest() {
return $this->cacheDocument;
}
}
//---- code snippet showing usage within a class
//$document is a cached SOAP response document from a previous request, saved with
SoapClient::__getLastResponse() to some cache somewhere
//for the purpose of this example, it is assumed that $this->wsdl, $this->options,
$this->method and $this->params are set.
public function SoapRequest($document) {
$method = $this->method;
if($document == "") {
//uncached
try {
//default options
$client = new SoapClient($this->wsdl, $this->options);
$result = $client->$method($this->params);
//send the response to the cache
$this->CacheResponse($client->__getLastResponse());
} catch(SoapFault $fault) {
//log something
return FALSE;
}
} else {
//cached document
try {
/**
* the WSDL needs to be set to allow the method to be called on the client object
* and to trigger SoapClient to decode the response to native data types
*/
$client = new YourNamespace_SoapClient_Local($this->wsdl, $this->options);
$client->SetCacheDocument($document);
$result = $client->$method($this->params);
} catch (SoapFault $fault) {
//log something
return FALSE;
}
}
return $result;
}
?>
I'll leave you to work out the caching, plenty of options there.. ;)
----
Server IP: 203.202.10.60
Probable Submitter: 58.6.148.157
----
Manual Page -- http://www.php.net/manual/en/function.soap-soapclient-dorequest.php
Edit -- https://master.php.net/note/edit/80852
Del: integrated -- https://master.php.net/note/delete/80852/integrated
Del: useless -- https://master.php.net/note/delete/80852/useless
Del: bad code -- https://master.php.net/note/delete/80852/bad+code
Del: spam -- https://master.php.net/note/delete/80852/spam
Del: non-english -- https://master.php.net/note/delete/80852/non-english
Del: in docs -- https://master.php.net/note/delete/80852/in+docs
Del: other reasons-- https://master.php.net/note/delete/80852
Reject -- https://master.php.net/note/reject/80852
Search -- https://master.php.net/manage/user-notes.php