Page 1 of 1

Timeout using Fsock

Posted: Wed Oct 16, 2013 2:10 pm
by guillaume.boissiere
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?

Re: Timeout using Fsock

Posted: Wed Oct 16, 2013 6:23 pm
by kamermans
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
}