How to specify a backup remote webservice?

Using Tera-WURFL's Remote Webservice Client. This includes the pre-packaged clients that come with Tera-WURFL and any other client you may have made to use the webservice.

How to specify a backup remote webservice?

Postby jhodgski » Sat Apr 09, 2011 9:52 am

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
jhodgski
 
Posts: 20
Joined: Wed Apr 06, 2011 11:42 am

Re: How to specify a backup remote webservice?

Postby kamermans » Sat Apr 09, 2011 12:16 pm

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);
}
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: How to specify a backup remote webservice?

Postby jhodgski » Sat Apr 09, 2011 4:47 pm

Nice one, thanks.
jhodgski
 
Posts: 20
Joined: Wed Apr 06, 2011 11:42 am


Return to Using the Remote Webservice

Who is online

Users browsing this forum: No registered users and 2 guests

cron