Skip to Main Content
Official App
Free – Google Play
Get it
FreshBooks is Loved by American Small Business Owners
FreshBooks is Loved by Canadian Small Business Owners
FreshBooks is Loved by Small Business Owners in the UK
Dev Blog

Are you using Keep-Alive?

by Taavi on January 30/2009

Do you use the FreshBooks API? Do you make multiple requests in a session? Is it painful waiting for each and every request to complete?

If so, you have to ask if you’re getting the best performance out of the API. When one piece of work at your end may entail 3-4 API requests, the average speed of making requests can have a big impact on your own application’s performance.

Our web servers are set up to allow HTTP persistent connections which eliminates the delay of opening a new HTTP connection (and renegotiating SSL!) for each API request.

In our own testing, this can result in up to 50% time savings over the course of a multi-request interaction! For example, cURL in PHP automatically takes advantage of persistent connections, if you don’t force it to make a new connection each time:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_USERPWD, $token);
$request = get_first_request();
while ($request) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$request = get_next_request($response = curl_exec($ch));

Ben’s looking to update the FreshBooks Ruby wrapper to make use of persistent connections. Enjoy!