Page 1 of 1

How to specify a backup remote webservice?

PostPosted: Sat Apr 09, 2011 9:52 am
by jhodgski
How can I specify a backup remote webservice?

Existing code snippet:
Code: Select all
require_once('./TeraWurflRemoteClient.php');
$data_format = TeraWurflRemoteClient::$FORMAT_JSON;
$timeout = 1;
$method = TeraWurflRemoteClient::$METHOD_CURL; //other option is $METHOD_URL_WRAPPER
$wurflObj = new TeraWurflRemoteClient('http://myPrimaryServer.co.uk/Tera-WURFL/webservice.php',$data_format,$timeout,$method);
$capabilities = array("resolution_width|xhtml_support_level");
$wurflObj->getCapabilitiesFromAgent(TeraWurflRemoteClient::getUserAgent(),$capabilities);


Required code, something along the lines of:
Code: Select all
require_once('./TeraWurflRemoteClient.php');
$data_format = TeraWurflRemoteClient::$FORMAT_JSON;
$timeout = 1;
$method = TeraWurflRemoteClient::$METHOD_CURL; //other option is $METHOD_URL_WRAPPER
$wurflObj;
try {
    $wurflObj = new TeraWurflRemoteClient('http://myPrimaryServer.co.uk/Tera-WURFL/webservice.php',$data_format,$timeout,$method);
}
catch(Exception $e1) {
    $wurflObj = new TeraWurflRemoteClient('http://myAlternativeServer.co.uk/Tera-WURFL/webservice.php',$data_format,$timeout,$method);
}
$capabilities = array("resolution_width|xhtml_support_level");
$wurflObj->getCapabilitiesFromAgent(TeraWurflRemoteClient::getUserAgent(),$capabilities);

...but if I specifiy a bad URI for myPrimaryServer, myAlternativeServer isn't used. I'm fairly new to PHP, so there could be an error in my code. Can anyone post a solution that would work?

Thanks,
James

Re: How to specify a backup remote webservice?

PostPosted: Sat Apr 09, 2011 12:16 pm
by kamermans
I think the actual call to the server takes place when you do the getCapabilitiesFromAgent() call.
This should work:

Code: Select all
require_once('./TeraWurflRemoteClient.php');
$data_format = TeraWurflRemoteClient::$FORMAT_JSON;
$timeout = 1;
$method = TeraWurflRemoteClient::$METHOD_CURL; //other option is $METHOD_URL_WRAPPER
$capabilities = array("resolution_width|xhtml_support_level");
try {
    $wurflObj = new TeraWurflRemoteClient('http://myPrimaryServer.co.uk/Tera-WURFL/webservice.php',$data_format,$timeout,$method);
   $wurflObj->getCapabilitiesFromAgent(TeraWurflRemoteClient::getUserAgent(),$capabilities);
}
catch(Exception $e1) {
    $wurflObj = new TeraWurflRemoteClient('http://myAlternativeServer.co.uk/Tera-WURFL/webservice.php',$data_format,$timeout,$method);
   $wurflObj->getCapabilitiesFromAgent(TeraWurflRemoteClient::getUserAgent(),$capabilities);
}

Re: How to specify a backup remote webservice?

PostPosted: Sat Apr 09, 2011 4:47 pm
by jhodgski
Nice one, thanks.