<?php require_once "../../lib/Dklab/SoapClient.php"; $client = new Dklab_SoapClient(null, array('location' => "http://dklab.ru/lib/Dklab_SoapClient/demo/test/Dklab_SoapClient/soapserver.php", 'uri' => 'urn:myschema', 'timeout' => 1)); try { // 4 is greater than timeout, so an exception will happen. $t0 = microtime(true); $client->slowMethod(3); } catch (Exception $e) { echo $e->getMessage() . sprintf(" in %.2fs", microtime(true) - $t0) . "\n"; }
<?php require_once "../../lib/Dklab/SoapClient.php"; $client = new Dklab_SoapClient(null, array('location' => "http://microsoft.com:8876", 'uri' => 'urn:myschema', 'response_validator' => 'responseValidator', 'timeout' => 1)); echo "<pre>"; try { $client->someMethod(); } catch (Exception $e) { echo $e->getMessage() . "\n"; } /** * Must return true if the response is valid, false if not and we need * to reconnect, or throw an exception if attemts limit is reached. */ function responseValidator($response, $numberOfAttempt) { if ($response['http_code'] != 200 || !strlen($response['body'])) { if ($numberOfAttempt < 3) { echo date("r") . ": Failed after {$numberOfAttempt} attempts, retrying...\n"; return false; } else { throw new SoapFault("Client", date("r") . ": Exception: failed after {$numberOfAttempt} attempts!"); } } return true; }
<?php require_once "../../lib/Dklab/SoapClient.php"; $client = new Dklab_SoapClient(null, array('location' => "http://dklab.ru/lib/Dklab_SoapClient/demo/test/Dklab_SoapClient/soapserver.php", 'uri' => 'urn:myschema', 'timeout' => 3)); $data = $client->getComplexData(array("abc")); // call MyServer::getComplexData() $text = $client->slowMethod(1); // call MyServer::slowMethod() echo "<pre>"; print_r($data); print_r($text);