Skip to content

Instantly share code, notes, and snippets.

@mudge
Last active August 29, 2015 14:19
Show Gist options
  • Save mudge/2a4f82b5be51541d9303 to your computer and use it in GitHub Desktop.
Save mudge/2a4f82b5be51541d9303 to your computer and use it in GitHub Desktop.
How to set request timeouts for various network clients
Faraday.new(site, request: { timeout: 30 })
<?php
new \GuzzleHttp\Client([
'base_url' => $url,
'defaults' => ['timeout' => 1]
]);
<?php
new \Guzzle\Http\Client($url, ['request.options' => ['timeout' => 30]]);
HTTParty.get(url, timeout: 30)
Koala.http_service.http_options = {
request: { timeout: 30 }
}
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 10
http.open_timeout = 1
OAuth2::Client.new(id, secret, site: site, connection_opts: { request: { timeout: 30 } })
# It doesn't look like RestClient.get supports passing timeouts
RestClient::Request.execute(method: :get, url: url, timeout: 30)
Typhoeus.get(url, timeout: 30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment