I am writing a PHP application that uses several SOAP web services to collect data.
I get significant overhead when creating all these objects: in some cases, one line of code $object = new SoapClient($wsdl); may take more than three seconds. Obviously, only a few of them make the web page very slow.
To speed things up a bit, I decided that I would serialize the objects and save them in the session (or somewhere similar), so I wrote the following function:
function soap_client($name,$wsdl) { if (!isset($_SESSION['soapobjects'][$name])) { $client = new SoapClient($wsdl, array('trace' => 1)); $_SESSION['soapobjects'][$name]=serialize($client); } else { $client = unserialize($_SESSION['soapobjects'][$name]); } return $client; }
This certainly looks like the way PHP recommends .
... and then calling it that ...
$client = soap_client('servicename',$wsdl); $client->MethodName($parameters);
However, it does not work.
At the first start, it works (i.e. an object is created and a serialized copy is created, and the method call works fine). However, the second time you run it, it fails.
The object looks serialized and deserizable correctly, but when you try to make a SOAP call on a de-serialized object, it throws the following error:
Fatal error: Uncaught SoapFault exception: [Client] Error finding "uri" property
Obviously, the de-serialized object does not match the original object, which contradicts the way that serializing objects is supposed to work.
Can someone explain why I am getting this error? Can you suggest a way to make it work or an alternative strategy that I could convince?
Thanks.
ps - I tried to solve the problem, but not joy.
I tried to specify the URI in the parameter parameter (as indicated in the PHP SOAP Client manual ), but it did not make any difference. But in any case, this is not necessary, since I use WSDL.
I also tried just copying the object to $_SESSION without using serialize() and deserialize() , but it has exactly the same effect.