Timeout using Fsock

Questions about the WURFL Cloud service.
guillaume.boissiere
Posts: 5
Joined: Thu Oct 10, 2013 12:32 pm

Timeout using Fsock

Postby guillaume.boissiere » Wed Oct 16, 2013 2:10 pm

I need to process a lot of data and I want to make sure that the API will not return a server error or a Exception like WurflCloud_Client_HttpException .
Does the API have a way to change the timeout of the service?

kamermans
Posts: 393
Joined: Mon Jun 06, 2011 9:50 am

Re: Timeout using Fsock

Postby kamermans » Wed Oct 16, 2013 6:23 pm

Due to a bug in the WURFL Cloud Client code, the default method of adjusting the timeout is not honored, but version 2 of the client is finished, and we're just days away from release. Note, however, that the new client for PHP will require some minor changes since the new library is namespaced.

In the meantime, you can extend the included fsock HTTP class to adjust the timeout:

Code: Select all

class CustomHttpClient extends WurflCloud_HttpClient_Fsock {
	// Set time in milliseconds (10000 = 10 seconds)
	protected $timeout_ms = 10000;
}
Then you can tell the client to use this client:

Code: Select all

$config = new WurflCloud_Client_Config();
$config->http_method = 'CustomHttpClient';
$config->api_key = '123456:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client = new WurflCloud_Client_Client($config);
Note that increasing the timeout will not guarantee that no exceptions will be thrown. For example, on my local test machine (Ubuntu Linux), there is a local DNS proxy that occasionally fails, which causes a DNS error, which results in an exception in the client. If you really want to catch all the exceptions, you'll need to wrap your code in a try/catch block:

Code: Select all

try {
	$client->detectDevice();
} catch (Exception $e) {
	// Client threw exception, do something more graceful here
}
Thanks,

Steve Kamerman
ScientiaMobile

Make sure you check out our WURFL Cloud, WURFL InSight and WURFL InFuze products!


Who is online

Users browsing this forum: No registered users and 22 guests